Fw: [PHP-GENERAL] Preserving Decimals

From: Date: Fri, 16 Jun 2000 22:01:23 +0000
Subject: Fw: [PHP-GENERAL] Preserving Decimals
Groups: php.general 
Request: Send a blank email to php-general+get-2105@lists.php.net to get a copy of this message
Yoed, PHP displays the fewest decimals possible to show the value of a number. I would use either number_format() or printf() or sprintf() to maintain the decimal places I wanted. Example script: $a=5000; $b=4000; echo("number_format=" . number_format($a+$b,2) . "<BR>"); printf("printf=%0.2f",$a+$b); displays number_format=9,000.00 printf=9000.00 Regards, Carroll Barrett >-----Original Message----- >From: Yoed Anis <yoed@zarcrom.com> >To: php-general@lists.php.net <php-general@lists.php.net> >Date: Friday, June 16, 2000 4:28 PM >Subject: [PHP-GENERAL] Preserving Decimals > > >>Hello, >> >> PHP seems to do a funny thing when it adds empty decimals.. it >makes them >>disappear. >>So if I were to add 5.00 to 4.00 it would display 9, not 9.00 >>Or if I were to add 4.50 to 3.00 it would display 8.5 not 8.50 >>I have looked through the archives and my book for a solution to >this >>problem, since I thought it should be quiet common. After all >PHP is used in >>many commerce sites. >> >> So what is the simplest way to preserve decimals in a variable? >> >> Best Regards, >>Yoed >> >> P.S. >>please reply directly to me as well as the list. >> >> >> >>-- >>PHP General Mailing List (http://www.php.net/) >>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >>For additional commands, e-mail: php-general-help@lists.php.net >>To contact the list administrators, e-mail: >php-list-admin@lists.php.net >> > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#2105) next »