[PHP] number_format

2011-12-19 Thread Floyd Resler
In the previous version of PHP we were using, I could pass a string to 
number_format and it would just change it to a 0 without complaint.  With 5.3.6 
I get an expects double error.  I don't suppose there's a way to make it work 
like it used to???  I'm dealing with really old code that wasn't very well 
structured.

Thanks!
Floyd


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



Re: [PHP] number_format

2011-12-19 Thread Bastien Koert
On Mon, Dec 19, 2011 at 9:19 AM, Floyd Resler fres...@adex-intl.com wrote:
 In the previous version of PHP we were using, I could pass a string to 
 number_format and it would just change it to a 0 without complaint.  With 
 5.3.6 I get an expects double error.  I don't suppose there's a way to make 
 it work like it used to???  I'm dealing with really old code that wasn't very 
 well structured.

 Thanks!
 Floyd


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



Could you check it before formatting? Or if the data is coming from
the db, force it to 0 if null?

$var = (is_double($number_var)) ? $number_var : 0;



-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] number_format

2011-12-19 Thread Ken Robinson

Quoting Floyd Resler fres...@adex-intl.com:

In the previous version of PHP we were using, I could pass a string  
to number_format and it would just change it to a 0 without  
complaint.  With 5.3.6 I get an expects double error.  I don't  
suppose there's a way to make it work like it used to???  I'm  
dealing with really old code that wasn't very well structured.


The way I would get around this would be to create a function like this:

function my_number_format($number, $decimals = 0, $dec_point = '.',  
$thousands_sep = ',') {

   $number += 0;  //convert value to a number.
   return number_format($number, $decimals, $dec_point, $thousands_sep);
}

The just do a global replace of number_format with my_number_format.

That should work, although I haven't tested it...

Ken


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



Re: [PHP] number_format

2011-12-19 Thread Robert Cummings

On 11-12-19 11:08 AM, Bastien Koert wrote:

On Mon, Dec 19, 2011 at 9:19 AM, Floyd Reslerfres...@adex-intl.com  wrote:

In the previous version of PHP we were using, I could pass a string to number_format and 
it would just change it to a 0 without complaint.  With 5.3.6 I get an expects 
double error.  I don't suppose there's a way to make it work like it used to???  
I'm dealing with really old code that wasn't very well structured.

Thanks!
Floyd


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




Could you check it before formatting? Or if the data is coming from
the db, force it to 0 if null?

$var = (is_double($number_var)) ? $number_var : 0;


Or possibly:

?php

number_format( (float)$your_input, 2 );

?

Cheers,
Rob.







--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] number_format

2011-12-19 Thread Floyd Resler

On Dec 19, 2011, at 11:38 AM, Robert Cummings wrote:

 On 11-12-19 11:08 AM, Bastien Koert wrote:
 On Mon, Dec 19, 2011 at 9:19 AM, Floyd Reslerfres...@adex-intl.com  wrote:
 In the previous version of PHP we were using, I could pass a string to 
 number_format and it would just change it to a 0 without complaint.  With 
 5.3.6 I get an expects double error.  I don't suppose there's a way to 
 make it work like it used to???  I'm dealing with really old code that 
 wasn't very well structured.
 
 Thanks!
 Floyd
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 Could you check it before formatting? Or if the data is coming from
 the db, force it to 0 if null?
 
 $var = (is_double($number_var)) ? $number_var : 0;
 
 Or possibly:
 
 ?php
 
 number_format( (float)$your_input, 2 );
 
 ?
 
 Cheers,
 Rob.
 

That worked beautifully!

Thanks!
Floyd




[PHP] number_format

2006-05-30 Thread Jo�o C�ndido de Souza Neto
Hi.

I´m using the number_format function to format my currency numbers.

i.g.: number_format($var,2,,,.)

Anyone´ll knew to tell me if this function rounds the number according of 
decimals?

Thanks. 

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



Re: [PHP] number_format

2006-05-30 Thread Stut

João Cândido de Souza Neto wrote:

I´m having some troubles with the number_format function.

When i run a number_format(3000,2,,,.) if returns correctly, but when 
i try to run number_format(300,2,,,.) it returns the value formatted 
but with two spaces before.


Anyone knows how can i avoid this?
  


Look at your other code around the functions. The number_format is not 
outputting any spaces...


[EMAIL PROTECTED]:~$ php tmp.php
'3.000,00'
'300,00'


Another example of where a simple test script would have moved you 
closer to a solution without involving the rest of us.


-Stut

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



Re: [PHP] number_format

2006-05-30 Thread Stut

João Cândido de Souza Neto wrote:
If you look at carefuly, you´ll see that i´ve two problems in the same 
function.


1 - This function add blank spaces at the beginning of the string.
2 - This function rounds the $var value and it can causes meny troubles.


Ok, I've already checked that number_format will not output spaces based 
on the calls you gave. Here's that script since it seems you don't 
believe me - try it yourself...


?php
   // This tests whether number_format is adding spaces
   print '.number_format(3000,2,,,.).'\n;
   print '.number_format(300,2,,,.).'\n;
?

As for the rounding thing, it does appear that number_format will round 
the number before displaying it. To avoid this you'll need to manipulate 
the number using the string functions.


-Stut

PS. Please do not just reply to me directly.

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



Re: [PHP] number_format

2006-05-30 Thread Jo�o C�ndido de Souza Neto
I´m sorry.

My head´s crazy todar.

Thanks a lot.

Stut [EMAIL PROTECTED] escreveu na mensagem 
news:[EMAIL PROTECTED]
 João Cândido de Souza Neto wrote:
 If you look at carefuly, you´ll see that i´ve two problems in the same 
 function.

 1 - This function add blank spaces at the beginning of the string.
 2 - This function rounds the $var value and it can causes meny troubles.

 Ok, I've already checked that number_format will not output spaces based 
 on the calls you gave. Here's that script since it seems you don't believe 
 me - try it yourself...

 ?php
// This tests whether number_format is adding spaces
print '.number_format(3000,2,,,.).'\n;
print '.number_format(300,2,,,.).'\n;
 ?

 As for the rounding thing, it does appear that number_format will round 
 the number before displaying it. To avoid this you'll need to manipulate 
 the number using the string functions.

 -Stut

 PS. Please do not just reply to me directly. 

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



[PHP] number_format

2006-05-29 Thread Jo�o C�ndido de Souza Neto
Hi.

I´m having some troubles with the number_format function.

When i run a number_format(3000,2,,,.) if returns correctly, but when 
i try to run number_format(300,2,,,.) it returns the value formatted 
but with two spaces before.

Anyone knows how can i avoid this?

Thanks. 

-- 
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




[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




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




[PHP] number_format

2002-03-08 Thread Scott St. John

Hi everyone,

I am trying to format a number for a report, the one consistant thing is 
the three decimal places.  But I need to strip them, then fill in zero's 
from the left.  

So, if the number coming in is 8.000 I need to convert to 00800, 11.070 
would convert to 01107.

I have tried a combination of number_format and usually end up with 8000
or 00110.  

Help!  Thank you!  Mind in slow motion this morning.

-Scott


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




RE: [PHP] number_format

2002-03-08 Thread Alastair Battrick

why not multiply the number by 1000 and then use
str_pad($in,6,0,STR_PAD_LEFT)

Alastair Battrick
Senior Developer
Lightwood Consultancy Ltd
http://www.lightwood.net

 -Original Message-
 From: Scott St. John [mailto:[EMAIL PROTECTED]]
 Sent: 08 March 2002 17:02
 To: [EMAIL PROTECTED]
 Subject: [PHP] number_format


 Hi everyone,

 I am trying to format a number for a report, the one consistant thing is
 the three decimal places.  But I need to strip them, then fill in zero's
 from the left.

 So, if the number coming in is 8.000 I need to convert to 00800, 11.070
 would convert to 01107.

 I have tried a combination of number_format and usually end up with 8000
 or 00110.

 Help!  Thank you!  Mind in slow motion this morning.

 -Scott


 --
 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

2002-03-08 Thread Scott St. John

Ok, I think I got it using this:

$anum = number_format($fie31,2);
$anum = str_replace($replace_char, $replace_strings, $anum);



On Fri, 8 Mar 2002, Alastair Battrick wrote:

 why not multiply the number by 1000 and then use
 str_pad($in,6,0,STR_PAD_LEFT)
 
 Alastair Battrick
 Senior Developer
 Lightwood Consultancy Ltd
 http://www.lightwood.net
 
  -Original Message-
  From: Scott St. John [mailto:[EMAIL PROTECTED]]
  Sent: 08 March 2002 17:02
  To: [EMAIL PROTECTED]
  Subject: [PHP] number_format
 
 
  Hi everyone,
 
  I am trying to format a number for a report, the one consistant thing is
  the three decimal places.  But I need to strip them, then fill in zero's
  from the left.
 
  So, if the number coming in is 8.000 I need to convert to 00800, 11.070
  would convert to 01107.
 
  I have tried a combination of number_format and usually end up with 8000
  or 00110.
 
  Help!  Thank you!  Mind in slow motion this morning.
 
  -Scott
 
 
  --
  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

2002-03-08 Thread Anas Mughal

Look into printf and sprintf.



--- Scott St. John [EMAIL PROTECTED] wrote:
 Hi everyone,
 
 I am trying to format a number for a report, the one
 consistant thing is 
 the three decimal places.  But I need to strip them,
 then fill in zero's 
 from the left.  
 
 So, if the number coming in is 8.000 I need to
 convert to 00800, 11.070 
 would convert to 01107.
 
 I have tried a combination of number_format and
 usually end up with 8000
 or 00110.  
 
 Help!  Thank you!  Mind in slow motion this morning.
 
 -Scott
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

-- 
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

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]




Re: [PHP] number_format() buggy round when usind database resultset

2001-01-26 Thread Richard Lynch

 I'm finding some problems on using number_format($value, $decimal, ",",
 ".") when I have a value comming from a resultset (database query
 results)...
 If I had something like '123.45', using number_format it will return
 '123,00'.
 I think this happens because my value is a string and PHP rounds it
 before using it on number_format. If I try to change the data type like
 (double) $value, I will also have a '123.00' result.
 I could do something on database like 'to_char(FIELD, '999G999D99') but
 database default is '.' for decimal separator and ',' for thousand
 separator...and I want the opposite.
 Suggestions/Solutions? :)

Your database may have a number_format() function that can better interact
with the internal data of the database.

--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
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]