VJS VJS - 6 months ago 11
PHP Question

formatting round value with 2 decimal in php

Have to round the number in php.
I have tried like below,

round(12.4569,2);


it will return 12.46. its OK.

But,
round(12.4003,2);

the output is 12.4

But need the output 12.40

suggestion please...

Answer

Use number_format :

number_format((float)$number, 2, '.', '');
Comments