I have a Ruby String that contains decimal-containing numbers. What's the best way to convert this into a decimal (fixed-point)?
"Best" means:
- Reliable given a wide range of input options
- Simple to write
- Easy to read
- DRY
...in roughly that order.
I have a Ruby String that contains decimal-containing numbers. What's the best way to convert this into a decimal (fixed-point)?
"Best" means:
...in roughly that order.
(Found it myself after a bit of digging)
BigDecimal is the standard Ruby fixed-point type, and it's constructor takes a String and handles the parsing for you:
BigDecimal.new("123.45")