P is for Practical PerlMonks

### Re: Fucking sprintf rounding - how does it work?

by daxim (Chaplain)
 on Sep 03, 2012 at 16:38 UTC ( #991473=note: print w/replies, xml ) Need Help??

in reply to F***ing sprintf rounding - how does it work?

round towards even, and for me, 0.15 => 0.2.

In the cases where your test program deviates from the expected value, it's just the usual floating point inaccuracy bullshit. I guess sprintf %f operates on NV/numbers.

• Comment on Re: Fucking sprintf rounding - how does it work?

Replies are listed 'Best First'.
Re^2: Fucking sprintf rounding - how does it work?
by ribasushi (Monk) on Sep 03, 2012 at 17:07 UTC
Could you please get the output of this on your CPU?
Certainly.
```\$ perl -e'printf qq[%s => %.68f => %.1f\n], (qq[0.\${_}5]) x 3 for (0..
+9)'
0.05 => 0.050000000000000000000677626357803440271254658000543713569641
+11328125 => 0.1
0.15 => 0.150000000000000000005421010862427522170037264004349708557128
+90625000 => 0.2
0.25 => 0.250000000000000000000000000000000000000000000000000000000000
+00000000 => 0.2
0.35 => 0.349999999999999999994578989137572477829962735995650291442871
+09375000 => 0.3
0.45 => 0.449999999999999999989157978275144955659925471991300582885742
+18750000 => 0.4
0.55 => 0.550000000000000000010842021724855044340074528008699417114257
+81250000 => 0.6
0.65 => 0.649999999999999999978315956550289911319850943982601165771484
+37500000 => 0.6
0.75 => 0.750000000000000000000000000000000000000000000000000000000000
+00000000 => 0.8
0.85 => 0.850000000000000000021684043449710088680149056017398834228515
+62500000 => 0.9
0.95 => 0.949999999999999999989157978275144955659925471991300582885742
+18750000 => 0.9
[download]```

```\$ perl -V
[download]```

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991473]
help
Chatterbox?
 [vedagiri89]: that is what i can't getting solution [vedagiri89]: recently purchased centos server and doing migration of app [choroba]: did you copy any dependencies? [choroba]: all XS code needs to be recompiled [vedagiri89]: install perl5.16 in the new server and try to run appache [hippo]: Which version of CentOS? [vedagiri89]: how to fix: Attempt to reload DynaLoader.pm aborted [hippo]: Ah, presumably 7 then.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-06-19 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (113 votes). Check out past polls.

Notices?