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
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
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
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:
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
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
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
]
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
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
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;
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 ?
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,
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
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.
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
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,
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
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
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:
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
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
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
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 );
, 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
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 =
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 =
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
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
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
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,
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 =
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:
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
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
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
$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';
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
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:
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
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
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,
41 matches
Mail list logo