Re: [PHP] sprintf thousand separator.

2009-02-11 Thread chris smith
2009/2/11 João Cândido de Souza Neto j...@consultorweb.cnt.br: Hello everybody. I´d just like to know if there´s any way of defining a thousand separator to a currency value using sprintf. Use number_format instead of sprintf, it's designed to do what you want. -- Postgresql php tutorials

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Jo�o C�ndido de Souza Neto
Chris, Thanks for your answer, but my real problem is to get thousand separator in jpgraph class which uses sprintf to display almost everithing; chris smith dmag...@gmail.com escreveu na mensagem news:3c1395330902110457i18cec69cy9818e08cdd3ff...@mail.gmail.com... 2009/2/11 João Cândido de

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Per Jessen
chris smith wrote: 2009/2/11 João Cândido de Souza Neto j...@consultorweb.cnt.br: Hello everybody. I´d just like to know if there´s any way of defining a thousand separator to a currency value using sprintf. Use number_format instead of sprintf, it's designed to do what you want. I

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Richard Heyes
Thanks for your answer, but my real problem is to get thousand separator in jpgraph class which uses sprintf to display almost everithing; Can you format it first, and then pass it to JPGraph ? -- Richard Heyes HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari:

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Jo�o C�ndido de Souza Neto
No, I can´t, because if I do it how can jpgrhph render without numeric data? hehehe Richard Heyes rich...@php.net escreveu na mensagem news:af8726440902110523x63ce5485p6534d10063eb4...@mail.gmail.com... Thanks for your answer, but my real problem is to get thousand separator in jpgraph

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Bruno Fajardo
Can you extend the JPGraph class, intercepting the desired method, formatting the output the way you need? 2009/2/11 João Cândido de Souza Neto j...@consultorweb.cnt.br No, I can´t, because if I do it how can jpgrhph render without numeric data? hehehe Richard Heyes rich...@php.net escreveu

Re: [PHP] sprintf thousand separator.

2009-02-11 Thread Jo�o C�ndido de Souza Neto
Ok, thanks. I´ll try to do it. As soon as I get it I´ll let you know. Thanks guys. Bruno Fajardo bsfaja...@gmail.com escreveu na mensagem news:eeb6980b0902110534p22a8c75eqd98cceaf3a150...@mail.gmail.com... Can you extend the JPGraph class, intercepting the desired method, formatting the

Re: [PHP] sprintf problem... (with simplified code )

2008-03-23 Thread Richard
] To: PHP lists php-general@lists.php.net Cc: Subject: Re: [PHP] sprintf problem... (with simplified code ) Here is a simplifie version of my code : ?php $total = 0; $ht = 10.03; $vat = 19.6; $total += $ht*($vat/100+1); print(Total = .sprintf(%0.2f, $total)); $total += $ht*($vat/100+1); print

Re: [PHP] sprintf problem...

2008-03-23 Thread Daniel Brown
On Sat, Mar 22, 2008 at 3:37 PM, Richard [EMAIL PROTECTED] wrote: [snip=code!] When I have one item at 10.03, the result is : Total Vat = 1.97 - Total without vat = 10.03 Total with vat = 12.00 but if I have two items at 10.03 the result is : Total vat = 3.93 - Total without vat = 20.06

[PHP] sprintf problem...

2008-03-22 Thread Richard
Hello, I'm trying to write a invoice script but I have encountered a slight problem. Each product needs to be listed without tax, and at the end of the file I need to show the VAT. In France VAT is 19.6% So €10.03 without vat = €12.00 with vat. So I do this : $totalwithoutvat = 0;

Re: [PHP] sprintf problem... (with simplified code )

2008-03-22 Thread Richard
Here is a simplifie version of my code : ?php $total = 0; $ht = 10.03; $vat = 19.6; $total += $ht*($vat/100+1); print(Total = .sprintf(%0.2f, $total)); $total += $ht*($vat/100+1); print( - Total 2 = .sprintf(%0.2f, $total)); ? I get 12.00 and 23.99 ... what should I do to get 12.00 and 24.00 ?

Re: [PHP] sprintf() oddness

2007-12-03 Thread Andrew Ballard
On Dec 1, 2007 11:30 AM, tedd [EMAIL PROTECTED] wrote: At 7:10 AM -0500 12/1/07, Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case,

Re: [PHP] sprintf() oddness

2007-12-03 Thread tedd
At 2:04 PM -0500 12/3/07, Andrew Ballard wrote: Oh, man I'm having flashbacks to a flame war that broke out on a SQL Server board I read related to bankers rounding versus traditional rounding and which was more correct or accurate. :-) Andrew There really shouldn't be a debate on which

Re: [PHP] sprintf() oddness

2007-12-03 Thread Andrew Ballard
On Dec 3, 2007 3:29 PM, tedd [EMAIL PROTECTED] wrote: At 2:04 PM -0500 12/3/07, Andrew Ballard wrote: Oh, man I'm having flashbacks to a flame war that broke out on a SQL Server board I read related to bankers rounding versus traditional rounding and which was more correct or accurate.

Re: [PHP] sprintf() oddness

2007-12-02 Thread Christoph
The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprintf() basing it's decision on the value of the 3rd significant digit? If so, why? Shouldn't rounding decisions be based on subsequent digits and not preceding

Re: [PHP] sprintf() oddness

2007-12-02 Thread tedd
At 6:08 AM -0500 12/2/07, Christoph wrote: If the general rule is to round up for 5s when preceeding is odd and round down when even, that's not occuring here when using round(). No, you're not reading what I wrote. I said MY general rule is to round up when the preceding digit is even,

Re: [PHP] sprintf() oddness

2007-12-02 Thread Martin Alterisio
2007/12/1, Christoph Boget [EMAIL PROTECTED]: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? Welcome to the world of f floating point numbers. Discrete mathematics, leave all hope, ye that enter. It's the way floating point

[PHP] sprintf() oddness

2007-12-01 Thread Christoph Boget
Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprintf() basing it's decision on the value of the 3rd

Re: [PHP] sprintf() oddness

2007-12-01 Thread Per Jessen
Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? I am using PHP 4.3.11 I see the same behaviour in 5.2.4 /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

Re: [PHP] sprintf() oddness

2007-12-01 Thread Jochem Maas
Per Jessen wrote: Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? most likely it's an artifact of the fact that the binary representations of those floating point values are not exact e.g. 0.1575 is

Re: [PHP] sprintf() oddness

2007-12-01 Thread Per Jessen
Jochem Maas wrote: Per Jessen wrote: Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? most likely it's an artifact of the fact that the binary representations of those floating point values are not exact

Re: [PHP] sprintf() oddness

2007-12-01 Thread tedd
At 7:10 AM -0500 12/1/07, Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is

[PHP] sprintf() oddity

2006-04-18 Thread Chris Boget
What's going on here: $number = 50.1234567890; echo sprintf( '%.05f', $number ); result: 50.12346 $number = 5.1234567890; echo sprintf( '%.05f', $number ); result: 5.12305 $number = 5000.1234567890; echo sprintf( '%.05f', $number );

Re: [PHP] sprintf() oddity

2006-04-18 Thread Satyam
, the precision does not even reach the decimal part. - Original Message - From: Chris Boget [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, April 18, 2006 5:19 PM Subject: [PHP] sprintf() oddity What's going on here: $number = 50.1234567890; echo sprintf( '%.05f

Re: [PHP] sprintf() oddity

2006-04-18 Thread Richard Lynch
On Tue, April 18, 2006 10:19 am, Chris Boget wrote: What's going on here: $number = 50.1234567890; echo sprintf( '%.05f', $number ); result: 50.12346 $number = 5.1234567890; echo sprintf( '%.05f', $number ); result: 5.12305 $number =

Re: [PHP] sprintf and arrays.

2005-04-07 Thread Duncan Hill
On Wednesday 06 April 2005 18:05, Brent Baisley typed: You want to have sprintf look at the contents of the variable instead of the variable itself. Anytime you want to do something like this you use the eval() function to evaluate the contents of the variable. Woot! $begin_string =

[PHP] sprintf and arrays.

2005-04-06 Thread Duncan Hill
I have a snippet of code that looks something like: if (is_array($p_sub_values)) { foreach ($p_sub_values as $i = $v) { $p_sub_values_str[$i] = '$v'; } $s = join(',', $p_sub_values_str); $r = htmlentities(sprintf($tmp[0], $s, ENT_QUOTES); } $tmp[0] in this

Re: [PHP] sprintf and arrays.

2005-04-06 Thread Brent Baisley
For one, you are missing a right parenthesis ) in all of your examples. htmlentities( sprintf( $tmp[0], $s, ENT_QUOTES ) Second, the string you are trying to format only has one variable argument: $s. Fred likes %1$s on his %2$s You have it numbered for ordering, but you are still ordering

Re: [PHP] sprintf and arrays.

2005-04-06 Thread Duncan Hill
On Wednesday 06 April 2005 16:40, Brent Baisley wrote: For one, you are missing a right parenthesis ) in all of your examples. htmlentities( sprintf( $tmp[0], $s, ENT_QUOTES ) Meh, syntax blip from the cut and paste. Second, the string you are trying to format only has one variable

Re: [PHP] sprintf and arrays.

2005-04-06 Thread Brent Baisley
Making life groovy has been difficult since the 60's. You want to have sprintf look at the contents of the variable instead of the variable itself. Anytime you want to do something like this you use the eval() function to evaluate the contents of the variable. On Apr 6, 2005, at 12:46 PM,

Re: [PHP] sprintf and arrays.

2005-04-06 Thread Richard Lynch
On Wed, April 6, 2005 4:23 am, Duncan Hill said: I have a snippet of code that looks something like: if (is_array($p_sub_values)) { foreach ($p_sub_values as $i = $v) { $p_sub_values_str[$i] = '$v'; } $s = join(',', $p_sub_values_str); $r =

[PHP] Sprintf?

2005-03-29 Thread René Fournier
I need to go from 1754210747 (decimal) to 17 54 21 a7 47 (hex per character) Basically, reformat the string for each character, converting it to Hex, and spacing after each two characters. Sprintf? ...Rene -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

[PHP] sprintf troubles

2004-03-26 Thread Chris Thomas
Hey, Im trying to use sprintf to format a number and left pad it with spaces, but it doesnt want to add the spaces I can pad it with anyother char using sprintf(%'_8.2f, $val) which will left-pad the number with underscores Has anyone had any luck padding with spaces?? or is there a better way

Re: [PHP] sprintf troubles

2004-03-26 Thread Tom Rogers
Hi, Saturday, March 27, 2004, 1:31:33 AM, you wrote: CT Hey, CT Im trying to use sprintf to format a number and left pad it with spaces, but CT it doesnt want to add the spaces CT I can pad it with anyother char using sprintf(%'_8.2f, $val) which will CT left-pad the number with underscores

[PHP] sprintf

2002-11-07 Thread Tyler BIRD
hey I'm trying to make dynamic database queries using sprintf any way I can get around this error? $sql = SELECT * FROM Vacation where StartDate LIKE '%s/ . '\%' . /%s'; $sql = sprintf($sql, $_GET[month], $_GET[year] ); I want just a literal slash between the month and year, printf seems to

Re: [PHP] sprintf

2002-11-07 Thread Robert Cummings
$sql = SELECT * FROM Vacation where StartDate LIKE '%s\\%s'; That should work :) Cheers, Rob. Tyler BIRD wrote: hey I'm trying to make dynamic database queries using sprintf any way I can get around this error? $sql = SELECT * FROM Vacation where StartDate LIKE '%s/ . '\%' . /%s';

[PHP] sprintf() question

2002-08-29 Thread SpamSucks86
I read the manual page on sprintf, but I still don't understand exactly how the format string works. $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output 123.1; $formatted = sprintf(%01.2f, $money); // echo $formatted will output 123.10 How does that

Re: [PHP] sprintf() question

2002-08-29 Thread @ Edwin
Experiment a bit and I'm sure you'll find it easy. One example, change this portion $formatted = sprintf("%01.2f", $money); to $formatted = sprintf("%01.3f", $money); then see how it works... ?php $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; echo "This is money:

[PHP] sprintf precision modifiers

2002-03-05 Thread Erik Price
The manual for sprintf http://www.php.net/manual/en/function.sprintf.php gives a nice introduction to the idea of the different formatting options. But, the reader is referred to the examples to see the different ways that you can format a number. Is there a better resource than this for

[PHP] sprintf()'s in if()'s

2001-05-04 Thread Chris Cameron
I suppose when you have so few problems you get to nitpick.. Guess my question is; why doesn't this work? if(sprintf(%01.2f,$Result[CurrentPrice]+$Result[Increment]) = sprintf(%01.2f,$BidAmt)) { when this works; if(0.30 = 1.00) { I'll just settle with a workaround for now. Thanks, Chris

Re: [PHP] sprintf()'s in if()'s

2001-05-04 Thread Jason Brooke
I suppose when you have so few problems you get to nitpick.. Guess my question is; why doesn't this work? if(sprintf(%01.2f,$Result[CurrentPrice]+$Result[Increment]) = sprintf(%01.2f,$BidAmt)) { when this works; if(0.30 = 1.00) { I'll just settle with a workaround for now. Thanks,