Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i round in php with keeping the two zeros

Tags:

php

rounding

I have this php

<?php echo round($price, 2); ?> 

and the $price maybe 1.0000

i want 1.00 but i get only 1

any ideas

like image 712
Matt Elhotiby Avatar asked Sep 21 '11 00:09

Matt Elhotiby


People also ask

How do I round up in PHP?

The ceil() function rounds a number UP to the nearest integer, if necessary. Tip: To round a number DOWN to the nearest integer, look at the floor() function. Tip: To round a floating-point number, look at the round() function.

How do you round a percentage in PHP?

echo round($fakecount * 100 / $totalcount); You are calculating $fakecount / $totalcount , which will be a number between 0 and 1, then you round that, so you get either 0 or 1, then you multiply by 100, giving either 0 or 100 for your percentage.


1 Answers

number_format works:

echo number_format($price, 2);

like image 152
John Godspeed Avatar answered Sep 19 '22 19:09

John Godspeed