VJS VJS - 1 year ago 74
PHP Question

formatting round value with 2 decimal in php

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


it will return 12.46. its OK.


the output is 12.4

But need the output 12.40

suggestion please...

Answer Source

Use number_format :

number_format((float)$number, 2, '.', '');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download