A concise way to create BigDecimals
Decimals are an important tool if you want reliable values to use in e.g. financial software. Ruby provides a BigDecimal class that you can use for this sort of thing. The normal way is to initialise it in the traditional manner:
BigDecimal.new("0.5")
But the most concise way to do it is with good, old-fashioned type coercion:
"0.5".to_d
You'll need to require BigDecimal before you can do this, but you were going to be doing that anyway, right? Hat tip to Daniel Sherson for the idea! - Daniel Zollinger











