Skip to content

End of Life Ruby 3.0 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 { ... }

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

See also .save_limit #% .save_exception_mode #* also in 3.3 · 3.2 · 3.1