Bluehost.com Web Hosting $6.95

PHP Equivalent of JavaScript whatever.toFixed(2)

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


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-08-2008
Arnie Shore
 
Posts: n/a
Default PHP Equivalent of JavaScript whatever.toFixed(2)

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
Reply With Quote
  #2 (permalink)  
Old 09-08-2008
Sjoerd
 
Posts: n/a
Default Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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.


$str = sprintf("%01.2f", $number);
Reply With Quote
  #3 (permalink)  
Old 09-09-2008
SLerman
 
Posts: n/a
Default Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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
Reply With Quote
  #4 (permalink)  
Old 09-09-2008
Ross McKay
 
Posts: n/a
Default Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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
Reply With Quote
  #5 (permalink)  
Old 09-09-2008
Jochem Maas
 
Posts: n/a
Default Re: [PHP] Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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



Reply With Quote
  #6 (permalink)  
Old 09-09-2008
Jochem Maas
 
Posts: n/a
Default Re: [PHP] Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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?

Reply With Quote
  #7 (permalink)  
Old 09-09-2008
Nathan Rixham
 
Posts: n/a
Default Re: [PHP] Re: PHP Equivalent of JavaScript whatever.toFixed(2)

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0