Try: number_format() Hugh ----- Original Message ----- From: "Sascha Cunz" <[EMAIL PROTECTED]> To: "Stephen" <[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, November 14, 2002 5:37 PM Subject: Re: [PHP] Subtracting Money
Hi Stephen, > I'm having a problem. I need to subtract money, but if they type in an > ammount such as $2.30 and I subtract $0.20, instead of returning $2.10 like > it should, it returns $2.1. How can I fix this keeping in mind that other > variable could be $2.40 or $100.30 and so on...? This is because, 2.1 is equal to 2.10 :-) You need to format the numbers in the way you want them. have a look at: http://www.php.net/manual/en/function.number-format.php and/or http://www.php.net/manual/en/function.sprintf.php both of them should do that job. sprintf's Example 6: $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output "123.1"; $formatted = sprintf("%01.2f", $money); // echo $formatted will output "123.10" -Sascha -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php