How to convert a string with an amount in dollars, for example, "5.32"or "100", into a whole amount in cents, such as 532or 10000?
I have a solution below:
dollar_amount_string = "5.32"
dollar_amount_bigdecimal = BigDecimal.new(dollar_amount_string)
cents_amount_bigdecimal = dollar_amount_bigdecimal * BigDecimal.new(100)
cents_amount_int = cents_amount_bigdecimal.to_i
but it seems awkward. I want to be sure, because it will be the entrance to the PayPal API.
I also tried the money stone, but it was not able to take the lines as inputs.
source
share