Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Rounding off numbers

by bulrush (Scribe)
on Jan 25, 2016 at 14:22 UTC ( [id://1153571]=note: print w/replies, xml ) Need Help??


in reply to Re: Rounding off numbers
in thread Rounding off numbers

<s>sprintf and printf no longer rounds sometime after Perl 5.8.8. It truncates. </s>

EDIT: I think I may have some bad information, which was corrected later on. If a calculation is done which results in 2.4999999999, sprintf("%.2f",2.49999999) would "round" to 2.49 for some reason, which appears to be truncation, but is actually a different problem. You may not be able to reproduce the problem by typing in 2.4999999. 2.49999999 has to be the result of a calculation.

Replies are listed 'Best First'.
Re^3: Rounding off numbers
by choroba (Cardinal) on Jan 25, 2016 at 14:28 UTC
    It truncates.
    Does it?
    $ perl -wE 'printf "%.3f\n", .0009 + $];' 5.023
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-24 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found