Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: Padding with sprintf changing number (updated)

by haukex (Archbishop)
on Sep 24, 2021 at 14:44 UTC ( [id://11136993]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Padding with sprintf changing number
in thread Padding with sprintf changing number

Yes, it could also be that $amt is intentionally something like 4887.14999..., so my statement above may be a little too certain (edited). That in Perl, rounding is often done with sprintf's %f instead of %d is a good point.

Update: Wait a minute - OP says they did $amt = sprintf("%.2f",$amt); before the $amt = $amt*100;, so the issue is pretty certainly that $amt was first something that rounds to 4887.15, which can't be represented accurately, and assuming $amt is the same as $amount in the root node, the cause of the issue is pretty clear.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found