End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
BigDecimal.save_rounding_mode
BigDecimal.save_rounding_mode { ... }
ext/bigdecimal/bigdecimal.c
View on GitHub ↗
static VALUE
BigDecimal_save_rounding_mode(VALUE self)
{
unsigned short const round_mode = VpGetRoundMode();
int state;
VALUE ret = rb_protect(rb_yield, Qnil, &state);
VpSetRoundMode(round_mode);
if (state) rb_jump_tag(state);
return ret;
}
Execute the provided block, but preserve the rounding mode
Example
BigDecimal.save_rounding_mode do BigDecimal.mode(BigDecimal::ROUND_MODE, :up) puts BigDecimal.mode(BigDecimal::ROUND_MODE) end
For use with the BigDecimal::ROUND_*
See BigDecimal.mode