You are here: Re: [PHP] showing the decimal places « PHP « IT news, forums, messages
Re: [PHP] showing the decimal places

Posted by Jochem Maas on 03/17/05 18:07

ross@aztechost.com 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.
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация