Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: problem with variables

by monkey_boy (Priest)
on Oct 19, 2005 at 08:47 UTC ( #501220=note: print w/replies, xml ) Need Help??

in reply to problem with variables

Try comparing your numbers to a fixed number of decimal places.
if (sprintf("%.3f",$x) == sprintf("%.3f",$y)) { print "IS equal to 3 dp\n"; };

This is not a Signature...

Replies are listed 'Best First'.
Re^2: problem with variables
by jeanluca (Deacon) on Oct 19, 2005 at 08:52 UTC
    Using sprintf("%.5f",$x) works!! thanks. But it is still strange that if there are more decimal numbers, why they are not printed to the screen ?


      Because they may be thirteen decimal places to the right hand side of the decimal point. If the number, for example, is converted back to base ten as "19.9490000000001", the output will show a rounded-off version that doesn't include the most insignificant digits. In other words, more precision is stored than is displayed. Part of the reason that not all digits are displayed is because of the high liklihood that they're tainted by base-2 to base-10 conversion errors.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2021-10-27 14:19 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (93 votes). Check out past polls.