Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Math::round not rounding correctly (simple)

by tye (Sage)
on Dec 23, 2014 at 20:01 UTC ( [id://1111221]=note: print w/replies, xml ) Need Help??


in reply to Math::round not rounding correctly

When the number is actually 3461.49999999999999382 it should be rounded to 3461 but might be displayed as simply "3461.5".

Edit 1 in response to at least the second "edit" labeled "Edit 2" above (for sanity's sake, please stop changing the root of this conversation):

perl -e 'print sprintf("%.20f",(3010*1.15))."\n"' # Outputs 3461.49999 +999999950000000

QED. (Now, maybe you'll go read and try to understand the stuff about floating point that was linked to quite a while ago?)

- tye        

Replies are listed 'Best First'.
Re^2: Math::round not rounding correctly (simple)
by bulrush (Scribe) on Dec 23, 2014 at 20:17 UTC
    You got 3461.49999999999950000000? Because I didn't.

    What's your OS name and version? What's your perl version? Perhaps we have a difference of some math library or something.

      You got 3461.49999999999950000000? Because I didn't.

      What's your OS name and version? What's your perl version? Perhaps we have a difference of some math library or something.

      (Prior node quoted in entirety due to rash of prior "edit"s.)

      So I edited my prior node to correct my mis-paste. Clearly "%.4f" would not yield that many trailing digits. To get 20 trailing digits, I clearly had used "%.20f" (which is what my node now shows). (I also replied as edits are not so easy to notice, naturally.)

      Please try again.

      - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-18 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found