Convert the number to decimal (i.e. 11 goes to 1.1, 115 goes to 1.15), then take the ceiling of the number, and then multiply it back. Example:
public static int roundByScale(int toRound) {
int scale = (int)Math.pow(10.0, Math.floor(Math.log10(toRound)));
double dec = toRound / scale;
int roundDec = (int)Math.ceil(dec);
return roundDec * scale;
}
In this case, if you enter 15, it will be divided by 10 to become 1.5, then rounded to 2, then the method will return 2 * 10, which is 20.
source
share