Re: keeping the last zero

From: Date: Mon, 17 May 2004 09:06:01 +0000
Subject: Re: keeping the last zero
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-186396@lists.php.net to get a copy of this message
Hi!
I have a list of products with prices e.g. $100 $100.50 (those are examples, they can be anything, not all prices have decimal) when I add those I get $200.5. Is there a way to get $200.50.
if it is okay for you to add $100+$100 and get $200.00 you could use printf("$%1.2f",$price1+$price2); or $str=sprintf("$%1.2f",$price1+$price2); HTH, Oliver Hankeln

« previous php.general (#186396) next »