Always round integer down and up
Posted: Wed Sep 10, 2008 9:49 am
Hi everyone
I wonder if you can help me with this, it's been frying my brain for a couple of hours
I have the ID of an item in a content management system, but I want to be checking that the author names the images properly according to the ID of the item, and puts them in the correct folder.
Folders are all named:
/500_599/
/600_699/
/700_799/
...
/1000_1099/
/1100_1199/
etc
So the images for post ID=1085, goes into the ../1000_1099/ folder
Normally I would use floor() and ceil() for this but they only operate on floating point rounding up/down to the whole number. It would be cool if there could be a precision parameter for floor/ceil like round() to give it a negative precision so they can operate on numbers like these.
Is there a way I can take the ID and round it down to get the lower limit, then round it up to get the upper limit of the folder name?
There's got to be a maths way of doing this, but I'm having real trouble here. Something like divide by 100 floor/ceil, then multiply by 100, subtracting 1 from ceil. But I just can't figure it out
Any ideas?
Thanks, B
I wonder if you can help me with this, it's been frying my brain for a couple of hours
I have the ID of an item in a content management system, but I want to be checking that the author names the images properly according to the ID of the item, and puts them in the correct folder.
Folders are all named:
/500_599/
/600_699/
/700_799/
...
/1000_1099/
/1100_1199/
etc
So the images for post ID=1085, goes into the ../1000_1099/ folder
Normally I would use floor() and ceil() for this but they only operate on floating point rounding up/down to the whole number. It would be cool if there could be a precision parameter for floor/ceil like round() to give it a negative precision so they can operate on numbers like these.
Is there a way I can take the ID and round it down to get the lower limit, then round it up to get the upper limit of the folder name?
There's got to be a maths way of doing this, but I'm having real trouble here. Something like divide by 100 floor/ceil, then multiply by 100, subtracting 1 from ceil. But I just can't figure it out
Any ideas?
Thanks, B