I have a text field where the user can enter a number, and I want to be able to convert the string to an integer or float based on the user input. Is there an easy way to do that in Ruby?
For example:
User Input: "123" -> Output: 123
User Input: "123.99" -> Output: 123.99
Use to_i or to_f on the string
irb(main):001:0> "13".to_i
=> 13
irb(main):002:0> "13".to_f
=> 13.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With