Barry
2007-07-19 15:54:44 UTC
Does anyone have a simple routine or idea, how to round off a float to
the nearest fixed pre-determined set of Integers, namely to the closest of
2,5,10,20,50,100,200,500,1000
Without compiling a whole bunch of "if" smaller than, bigger than for
each of those Integer's
Im thinking more in the lines of dividing the float, by 10, then take
the ABS value, and then multiply by 10 again etc....but one still needs
to determine with "if"'s which INT it is nearest to, and thus which
value to divide by, abs, and multiply by.
Maybe a series of do{} while(value < INT); in ascending order of INT's
might do it effectively?
Any ideas?
Thanks
Barry
the nearest fixed pre-determined set of Integers, namely to the closest of
2,5,10,20,50,100,200,500,1000
Without compiling a whole bunch of "if" smaller than, bigger than for
each of those Integer's
Im thinking more in the lines of dividing the float, by 10, then take
the ABS value, and then multiply by 10 again etc....but one still needs
to determine with "if"'s which INT it is nearest to, and thus which
value to divide by, abs, and multiply by.
Maybe a series of do{} while(value < INT); in ascending order of INT's
might do it effectively?
Any ideas?
Thanks
Barry