Re: round up to nearest...

2005-08-22 Thread Jeff 'japhy' Pinyan
On Aug 21, Bryan Harris said: Is this the best way to do simple integer round-ups? E.g. 3.2 -> 4? I've been using: $nines = 1 - 1/1e10; $value = 3.2; $roundedvalue = int($value + $nines); ... but it looks like $roundedvalue = $value + (-$value % 1) might be better??? That technique I show

Re: round up to nearest...

2005-08-22 Thread Rex Rex
For ordinary integers, if the rounding up is truly a "rounding" and not ceiling up to the nearest highest integer, then this should work: $n = 3.2; print sprintf("%d", $n); #this will print 3 To ceil the number, wherein 3.2 --> 4 then this would work. use POSIX; print ceil($n); # this will print

Re: round up to nearest...

2005-08-22 Thread Bryan Harris
Neat, I like it! Is this the best way to do simple integer round-ups? E.g. 3.2 -> 4? I've been using: $nines = 1 - 1/1e10; $value = 3.2; $roundedvalue = int($value + $nines); ... but it looks like $roundedvalue = $value + (-$value % 1) might be better??? - B > On Aug 19, Bryan Harris sai

Re: round up to nearest...

2005-08-21 Thread Jeff 'japhy' Pinyan
On Aug 19, Bryan Harris said: Is there a simple formula to round some value X up to the next multiple of some other value T? Generally speaking, you can do: $x + (-$x % $t) For 10 to round up to the next multiple of 3, it's 10 + (-10 % 3) which is 10 + 2 = 12. Likewise, for negative numb