This is a discussion on PHP Equivalent of JavaScript whatever.toFixed(2) within the PHP General forums, part of the PHP Programming Forums category; Folks, I need to take a given float value to, say, two decimals, as per subject JS. I've RTFM, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Sep 8, 3:52*pm, Arnie Shore <shor...@gmail.com> wrote:
> Folks, I need to take a given float value to, say, two decimals, as > per subject JS. *I've RTFM, but to no avail. > > Can someone HELP???? > > as http://www.php.net/round |
|
|||
|
Arnie Shore wrote:
>> Folks, I need to take a given float value to, say, two decimals, as per >> subject JS. I've RTFM, but to no avail. On Mon, 08 Sep 2008 22:03:54 +0200, Sjoerd wrote: >$str = sprintf("%01.2f", $number); Skinning cat, method two: $str = number_format($number, 2); -- Ross McKay, Toronto, NSW Australia "Let the laddie play wi the knife - he'll learn" - The Wee Book of Calvin |
|
|||
|
Ross McKay schreef:
> Arnie Shore wrote: >>> Folks, I need to take a given float value to, say, two decimals, as per >>> subject JS. I've RTFM, but to no avail. > > On Mon, 08 Sep 2008 22:03:54 +0200, Sjoerd wrote: >> $str = sprintf("%01.2f", $number); > > Skinning cat, method two: > > $str = number_format($number, 2); watch out with number_format() it will format according to the current locale unless you specify the decimal and thousands seperator char explicitly ... e.g. english: 1,000.00 dutch: 1.000,00 |
|
|||
|
Nathan Rixham schreef:
> Jochem Maas wrote: >> Ross McKay schreef: >>> Arnie Shore wrote: >>>>> Folks, I need to take a given float value to, say, two decimals, as >>>>> per >>>>> subject JS. I've RTFM, but to no avail. >>> >>> On Mon, 08 Sep 2008 22:03:54 +0200, Sjoerd wrote: >>>> $str = sprintf("%01.2f", $number); >>> >>> Skinning cat, method two: >>> >>> $str = number_format($number, 2); >> >> watch out with number_format() it will format according to the current >> locale >> unless you specify the decimal and thousands seperator char explicitly >> ... e.g. >> >> english: 1,000.00 >> dutch: 1.000,00 >> >> >> > maybe I'm reading this wrong but > http://uk2.php.net/manual/en/function.round.php > what about round(), what's the problem? |
|
|||
|
Jochem Maas wrote:
> Ross McKay schreef: >> Arnie Shore wrote: >>>> Folks, I need to take a given float value to, say, two decimals, as per >>>> subject JS. I've RTFM, but to no avail. >> >> On Mon, 08 Sep 2008 22:03:54 +0200, Sjoerd wrote: >>> $str = sprintf("%01.2f", $number); >> >> Skinning cat, method two: >> >> $str = number_format($number, 2); > > watch out with number_format() it will format according to the current > locale > unless you specify the decimal and thousands seperator char explicitly > ... e.g. > > english: 1,000.00 > dutch: 1.000,00 > > > maybe I'm reading this wrong but http://uk2.php.net/manual/en/function.round.php |