[PHP] number_format question

2002-10-31 Thread ed

I using number_format where I need to turn a number say "123456789" into
"123,456,789" and it works just fine. I also need it to strip the decimal
out if someone enters it. I.E "123456.00" would become "123,456"

the command I'm using right now is:

number_format($number, ",");

If I enter "123456.00" it comes out as "123". Did I miss something?

Thanks,

Ed



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Number_Format Question

2001-11-03 Thread Jeff Oien

I have a number like this 0.51 and I would like it to display without
the leading 0. How can I do this? Thanks.
Jeff Oien

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] number_format question

2002-10-31 Thread Jay Blanchard
[snip]
I using number_format where I need to turn a number say "123456789" into
"123,456,789" and it works just fine. I also need it to strip the decimal
out if someone enters it. I.E "123456.00" would become "123,456"

the command I'm using right now is:

number_format($number, ",");

If I enter "123456.00" it comes out as "123". Did I miss something?
[/snip]

You're missing an attribute, try

number_format($number, '', ',');

HTH!

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] number_format question

2002-10-31 Thread ed

 If I try that I get a wrong parameter count error.


Ed


On Thu, 31 Oct 2002, Jay Blanchard wrote:

> [snip]
> I using number_format where I need to turn a number say "123456789" into
> "123,456,789" and it works just fine. I also need it to strip the decimal
> out if someone enters it. I.E "123456.00" would become "123,456"
> 
> the command I'm using right now is:
> 
> number_format($number, ",");
> 
> If I enter "123456.00" it comes out as "123". Did I miss something?
> [/snip]
> 
> You're missing an attribute, try
> 
> number_format($number, '', ',');
> 
> HTH!
> 
> Jay
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] number_format question

2002-10-31 Thread Jay Blanchard
[snip]
 If I try that I get a wrong parameter count error.

[/snip]

number_format ( float number [, int decimals [, string dec_point [, string
thousands_sep]]])

number_format($number, 0, '', ',');

Try that ...

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] number_format question

2002-10-31 Thread ed

 Tried it. It works but crops everything after the first "," in the number
if you enter a number with commas. Works great if you don't enter any
commas.

What I need to be able to do:

IN   OUT
123456789 > 123,456,789
123456789.00 > 123,456,789
123,456,789.00 > 123,456,789

Ed


On Thu, 31 Oct 2002, Jay Blanchard wrote:

> [snip]
>  If I try that I get a wrong parameter count error.
> 
> [/snip]
> 
> number_format ( float number [, int decimals [, string dec_point [, string
> thousands_sep]]])
> 
> number_format($number, 0, '', ',');
> 
> Try that ...
> 
> Jay
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] number_format question

2002-10-31 Thread Martin Towell
what about str_replace(",", "", $str) before you pass the value to
number_format()?

-Original Message-
From: [EMAIL PROTECTED] [mailto:ed@;home.homes2see.com]
Sent: Friday, November 01, 2002 9:37 AM
To: Jay Blanchard
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] number_format question



 Tried it. It works but crops everything after the first "," in the number
if you enter a number with commas. Works great if you don't enter any
commas.

What I need to be able to do:

IN   OUT
123456789 > 123,456,789
123456789.00 > 123,456,789
123,456,789.00 > 123,456,789

Ed


On Thu, 31 Oct 2002, Jay Blanchard wrote:

> [snip]
>  If I try that I get a wrong parameter count error.
> 
> [/snip]
> 
> number_format ( float number [, int decimals [, string dec_point [, string
> thousands_sep]]])
> 
> number_format($number, 0, '', ',');
> 
> Try that ...
> 
> Jay
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] number_format question

2002-10-31 Thread John W. Holmes
>  Tried it. It works but crops everything after the first "," in the
number
> if you enter a number with commas. Works great if you don't enter any
> commas.

How many integers can you name that have commas in them??? In other
words, you have a string, so PHP converts it to an integer to pass to
number format. Thus you only get the integer part up to the first comma.

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] number_format question

2002-11-01 Thread Hugh Danaher
What you need to do with the input number is to do an ereg_replace() and
eliminate the commas from the string, then use the string variable where
needed.  Then, when you want to display the variable, use the
number_format() function.
Hope this helps,
Hugh

- Original Message -
From: <[EMAIL PROTECTED]>
To: "Jay Blanchard" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, October 31, 2002 2:36 PM
Subject: RE: [PHP] number_format question


>
>  Tried it. It works but crops everything after the first "," in the number
> if you enter a number with commas. Works great if you don't enter any
> commas.
>
> What I need to be able to do:
>
> IN   OUT
> 123456789 > 123,456,789
> 123456789.00 > 123,456,789
> 123,456,789.00 > 123,456,789
>
> Ed
>
>
> On Thu, 31 Oct 2002, Jay Blanchard wrote:
>
> > [snip]
> >  If I try that I get a wrong parameter count error.
> >
> > [/snip]
> >
> > number_format ( float number [, int decimals [, string dec_point [,
string
> > thousands_sep]]])
> >
> > number_format($number, 0, '', ',');
> >
> > Try that ...
> >
> > Jay
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Number_Format Question

2001-11-03 Thread Steve Werby

"Jeff Oien" <[EMAIL PROTECTED]> wrote:
> I have a number like this 0.51 and I would like it to display without
> the leading 0. How can I do this? Thanks.

There are lots of solutions.

$num = 0.51;

$num_parts = explode( '.', $num );
$num_new = '.' . $num_parts[1];

Or if it's always going to be a number b/w 0 and 1 then you could use
substr() to get the part you want.  You could also use something like
ereg_replace().  Someone else may have a solution that's better.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]