ruby-on-rails – Big Decimal syntactic sugar

Question: Question:

When dealing with decimal points, I BigDecimal to use Big Decimal instead of Float , but every time I use it
BigDecimal(1) and 1.to_d make the code hard to read, so is there any special syntactic sugar?

Or is it possible to treat notations such as 1.0 as BigDecimal instead of Float by making specific settings in Rails?

Answer: Answer:

In the case of embedded libraries such as Float and Rational, literals may be prepared because they are built into Ruby itself, but BigDecimal is not a built-in library of Ruby but a standard attached library, so I think that there is no dedicated syntax. increase.

Scroll to Top