I am assuming you know What Every Computer Scientist Should Know About Floating-Point Arithmetic, since you say "this fails due to the way floats are stored in memory". On the off-chance you (or a future reader) needs a refresher, I have included the link.
Since the prices are coming as floats-in-a-string, you have it easy: you should just be able to strip out the decimal point. Assuming it's always got exactly two digits following, $price_string =~ s/\.(\d{2})$/$1/;. After this, it will be in string and numeric form as integer cents. parv already posted a regex that just strips the decimal point from anywhere in the string.
Alternately, don't use the int, which does truncation; instead, use a round-to-nearest, like round of POSIX
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|