Re: Padding the decimals
| From: | Adam Bregenzer | Date: | Mon, 23 Feb 2004 02:24:19 +0000 |
| Subject: | Re: Padding the decimals | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178505@lists.php.net to get a copy of this message | ||
On Sun, 2004-02-22 at 21:14, Simon Fredriksson wrote:
> Is there any functions to pad the decimals in a number? There's round()
> to put it down to two decimals, but what if I want to take it up to two?
>
> Example:
>
> 5 -> 5.00
> 20 -> 20.00
> 4.3 -> 4.30
> etc.
I assume you mean adding zeros to the end for displaying, not for
further calculation? Look at printf[1] and sprintf[2]. Here's an
example:
printf("%.3f", 4.1) // 4.100
[1] http://www.php.net/printf
[2] http://www.php.net/sprintf
--
Adam Bregenzer
adam@bregenzer.net
http://adam.bregenzer.net/