// -1 -> 10's digit, -2 -> 100's digit, etc.
BigDecimal normalized = value.movePointRight(scale);
// ...round to that digit
BigDecimal rounded = normalized.setScale(0,mode);
// ...and shift the result back to the left (multiply by 10**(abs(scale)))
return new RubyBigDecimal(getRuntime(), rounded.movePointLeft(scale));
} else {
return new RubyBigDecimal(getRuntime(), value.setScale(scale, mode));
}
}