View Full Version : Rounding?
[D]Vincent
09-15-2002, 07:00 AM
How would you get a number to round if it went into a decimal, like let's say I have 100.2, how would i get that to automatically go to 100? Or is there not a way?
Admin
09-15-2002, 02:52 PM
PHP's round() function, or sprintf() for older versions.
[D]Vincent
09-15-2002, 03:38 PM
Thanks ^^
But umm.. with the round how would I use it? Like how would I get it to know that it goes a decimal over to round up to the nearest 1?
futureal
09-15-2002, 05:37 PM
You can use something like this:
// round number up
$roundedup = ceil($number);
// round number down
$roundeddown = floor($number);
// round to nearest
$roundednearest = round($number);
[D]Vincent
09-15-2002, 08:40 PM
Vincent]So if I did
$blah1 = $blah2 * "1.2";
And $blah1 ended up being let's say 366.6 and I did
$blah = round($blah1);
then it would round it to 367 correct?
futureal
09-16-2002, 09:19 PM
Correct. The round() function will always go to the nearest integer, while ceil() and floor() round up and down, respectively.
[D]Vincent
09-23-2002, 10:16 AM
What if blah1 ended up being 205 and didn't have a decimal? Then what would happen?
Admin
09-23-2002, 02:28 PM
If the number you are rounding is already an integer, it will stay the same. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.