# Changing numbers - PHP Development

I have the following numbers: 12.400 666.75 23 369.2 3.234 How can I make them have at least 2 decimal places? So, they will output: 12.40 666.75 23.00 269.20 3.234 Thanks in advance! -- - Zavaboy [email]zavaboyhotmail.com[/email] [url]www.zavaboy.com[/url]...

1. ## Changing numbers

I have the following numbers:

12.400
666.75
23
369.2
3.234

How can I make them have at least 2 decimal places?
So, they will output:

12.40
666.75
23.00
269.20
3.234

--

- Zavaboy
[email]zavaboyhotmail.com[/email]
[url]www.zavaboy.com[/url]

Zavaboy Guest

2. ## Re: [PHP] Changing numbers

* Thus wrote zavaboy (zavaboyhotmail.com):
> I have the following numbers:
>
> 12.400
> 666.75
> 23
> 369.2
> 3.234
>
> How can I make them have at least 2 decimal places?
> So, they will output:
>
> 12.40
> 666.75
> 23.00
> 269.20
> 3.234
>
[url]http://php.net/number_format[/url]
or
[url]http://php.net/printf[/url]

Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Curt Zirzow Guest

3. ## Re: [PHP] Changing numbers

Curt Zirzow wrote:
>* Thus wrote zavaboy (zavaboyhotmail.com):
>
>
>>I have the following numbers:
>>
>>12.400
>>666.75
>>23
>>369.2
>>3.234
>>
>>How can I make them have at least 2 decimal places?
>>So, they will output:
>>
>>12.40
>>666.75
>>23.00
>>269.20
>>3.234
>>
>>
What I dont understand is that your examples are not consitant. You
want 2 or more decimal positions, so as if there are more than 2, to
leave what exists. But your first example, you truncate the last 0. Is
that a typo, or intentional?

Justin Gruenberg Guest

4. ## RE: [PHP] Changing numbers

> From: justin gruenberg [mailto:justinice.kewlio.net]
> Subject: Re: [PHP] Changing numbers
>
>
> Curt Zirzow wrote:
>
> >* Thus wrote zavaboy (zavaboyhotmail.com):
> >
> >
> >>I have the following numbers:
> >>
> >>12.400
> >>666.75
> >>23
> >>369.2
> >>3.234
> >>
> >>How can I make them have at least 2 decimal places?
> >>So, they will output:
> >>
> >>12.40
> >>666.75
> >>23.00
> >>269.20
> >>3.234
> >>
> >>
>
> What I dont understand is that your examples are not consitant. You
> want 2 or more decimal positions, so as if there are more than 2, to
> leave what exists. But your first example, you truncate the
> last 0. Is
> that a typo, or intentional?

He wants two or more *significant* positions preserved. Show to at least
two decimal places, trailing zeroes truncated beyond the 2nd decimal place.

Roger B.A Klorese Guest

5. ## Re: [PHP] Changing numbers

Roger B.A Klorese wrote:
>>>* Thus wrote zavaboy (zavaboyhotmail.com):
>>>
>>>
>>>
>>>>I have the following numbers:
>>>>
>>>>12.400
>>>>666.75
>>>>23
>>>>369.2
>>>>3.234
>>>>
>>>>How can I make them have at least 2 decimal places?
>>>>So, they will output:
>>>>
>>>>12.40
>>>>666.75
>>>>23.00
>>>>269.20
>>>>3.234
>
>
> He wants two or more *significant* positions preserved. Show to at least
> two decimal places, trailing zeroes truncated beyond the 2nd decimal place.
I am not sure what he is after, but I don't think it has to do with
significant figures (if that is what you meant). If that was the case,
12.400 should remain 12.400. Trailing zeros to the right of a decimal
are significant.

6. ## RE: [PHP] Changing numbers

> Sent: Monday, July 21, 2003 2:45 PM
> To: Roger B.A Klorese
> Cc: 'justin gruenberg'; 'Curt Zirzow'; 'PHP-General'
> Subject: Re: [PHP] Changing numbers
>
>
> I am not sure what he is after, but I don't think it has to do with
> significant figures (if that is what you meant). If that was
> the case,
> 12.400 should remain 12.400. Trailing zeros to the right of a decimal
> are significant.
Perhaps. But he's saying that, for his purposes, they're not -- if anything
to the right of the last shown zero existed, it would be reflected in the
output.

Roger B.A Klorese Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•