[SOLVED] A number to the thousandths decimal place

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

[SOLVED] A number to the thousandths decimal place

Post 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...
Last edited by anthony88guy on Sat May 06, 2006 3:20 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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'.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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)
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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.
Post Reply