Watch this: you can chop-off with (int) too!
Quote:
quote:Originally posted by casper
how can I get Math.ceil (75) to become 80
or Math.ceil(125) to become 130...???
|
int theNumber = 10* (int)Math.ceil(oldNumber/10.0); // all data types
Quote:
quote:
also to Math.floor(25) to become 20
|
int theNumber = 10* (int)(oldNumber/10.0); // all data types
// You might combine these in a method like:
public static double roundNumber(double number, int digits, boolean roundUp)
{
double factor = Math.pow(10.0, digits); // digits=1, factor=10
if(roundUp)
return factor*(int)Math.ceil(number/factor);
return factor*(int)(number/factor); // else
}
// I didn't try this out, but it should work!
Cheerz!
Franz