Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0