Page 1 of 1

[SOLVED] A number to the thousandths decimal place

Posted: Sat May 06, 2006 1:19 pm
by anthony88guy
I would like to display '1' as '1.000', a number to the thousandths place. I have searched php.net but have failed in the search.

What function will yield these results?

Thanks...

Posted: Sat May 06, 2006 1:39 pm
by hawleyjr
http://us3.php.net/manual/en/function.number-format.php
number_format

(PHP 3, PHP 4, PHP 5)
number_format -- Format a number with grouped thousands

Posted: Sat May 06, 2006 2:57 pm
by anthony88guy
php.net wrote:number_format

(PHP 3, PHP 4, PHP 5)
number_format -- Format a number with grouped thousands
Description
string number_format ( float number [, int decimals [, string dec_point, string thousands_sep]] )

number_format() returns a formatted version of number. This function accepts either one, two or four parameters (not three):

If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.

Only the first character of thousands_sep is used. For example, if you use bar as thousands_sep on the number 1000, number_format() will return 1b000.
I don’t think this is what I’m looking for.

number_format: "Format a number with grouped thousands"

I want to add/remove decimal places to a number.
example1 wrote: If I have '52.1', I want it displayed as '52.100'.
example2 wrote:If I have '52.1001', I want it displayed as '52.100'.

Posted: Sat May 06, 2006 3:13 pm
by Oren
anthony88guy wrote:I don’t think this is what I’m looking for.
That's exactly what you are looking for!

Code: Select all

number_format($number, 3)

Posted: Sat May 06, 2006 3:19 pm
by anthony88guy
Oren wrote:
anthony88guy wrote:I don’t think this is what I’m looking for.
That's exactly what you are looking for!

Code: Select all

number_format($number, 3)
I stand corrected.