user111671 user111671 - 2 years ago 219
Javascript Question

What is the exact equivalent of JS: something.toFixed() in PHP?

If I have

in javascript ('a' being equal to 2.4232) what is the exact equivalent command in php to retrieve that? I searched for it but found no proper explanation appended to the answers.

Answer Source

I found that sprintf and number_format both round the number, so i used this:

$number = 2.4232;
$decimals = 3;
$expo = pow(10,$decimals);
$number = intval($number*$expo)/$expo; //  = 2423/100
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download