Hi,
How do ensure a data is not longer than 0.1 decimal places? thanks
| SitePoint Sponsor |





Hi,
How do ensure a data is not longer than 0.1 decimal places? thanks
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





Try this:
That should do the trick.Code:$var = 3.222222; $var = number_format($var, 1); echo($var); // Prints "3.2"![]()





Hmm
This is my code:
$average_rate = round($average_rate, 2);
Is it the same?
Its to two decimal places
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





It's not exactly the same. round() rounds the number off to the number of decimal places you specify, while number_format just cuts it down to the number of places you specify.
Here's an example:
See the difference?Code:$num = "3.456"; $num = round($num, 2); echo($num); // Prints "3.46" /* -------------------------------- */ $num2 = "3.456"; $num2 = number_format($num2, 2); echo($num2); // Prints "3.45"![]()





oh..icic..okie
I'll use round.
ahahz.its for statiscal uses
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
Bookmarks