Jump to content

[SOLVED] I need to raise the decimal amount in a math problem...


cwncool

Recommended Posts

I have a simple math problem.  When my script adds my two numbers, for example, "0.60" and "0.30", it displays "0.9".  Although that is correct, this is dealing with money, so I need it to add up to "0.90".  Is there something I can do to make this add always with 2 decimal places?  Thanx!

What I mean is this:

 

<?
$a = 99999999999.99;
print "$a\n";
?>

 

On my system this prints out 100000000000.

 

As long as you only use small values, and you don't do any tricky maths, you should be ok :)  The reason for this is that floating point numbers (numbers with a "." in them) only have limited accuracy.  When the numbers are large, they start dropping decimal places in order to store the digits to the left of the dot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.