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

Viewed 29933

If I have a.toFixed(3); 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.

8 Answers

The straight forward solution is to use in php is number_format()

number_format(2.4232, 3);

how about this

    function to_fixed($number, $decimals) {
        return floatval(number_format($number, $decimals, '.', ""));
    }

call it like this

to_fixed(2.4232, 3); //  2.423
Related