----- Original Message -----
From: "Sascha Cunz" <[EMAIL PROTECTED]>
To: "Stephen" <[EMAIL PROTECTED]>; "PHP List"
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
> 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:

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"


PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to