Haj Mohamed  A Haj Mohamed A -4 years ago 83
PHP Question

Round with 0 decimal point

My variable is:

$No = '9.80000000000'

I want a result like this:
$No = '9.80'

I tried to use the round function with 2 decimal points, but I get results like this:
$No = '9.8'

I want to have a specific numeric scale precision.

My expected result is:
$No = '9.80'

Answer Source

round() function omits last digit zero so better use the number_format() function.


round($No,2)    //your code.

change this function to like below


number_format($No, 2);

I hope it will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download