Re: showing the decimal places

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ross@xxxxxxxxxxxxx wrote:
when I define a number as

$number = 2.00

then echo it the number shows as 2. How can I get the two zeros to show?

This is not in any of my books but a fairly easy solution I'll bet!

please consider php.net as your book too ;-)

have fun with the following:

<?php

$newLine = ($viaWeb = isset($_SERVER["HTTP_HOST"]))
	 ? "<br />"
 	 : "\n";

$number = 2.00;

echo $number; 					echo $newLine;
var_dump( $number );				if ($viaWeb) { echo $newLine; }
printf("%0.2f", $number); 			echo $newLine;
echo number_format( $number, 2 ); 		echo $newLine;
echo sprintf("%01.2f", $number); 		echo $newLine;
echo number_format(123456789, 2, ",", " "); 	echo $newLine;


R.



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux