Answers for "ruby string to numebr"

3

integer to string ruby

my_int = 69
my_int_to_string = my_int.to_s

puts my_int.class # Integer
puts my_int_to_string.class # String
Posted by: Guest on July-17-2020
3

ruby string to int

a = "42" # => '42'
a.to_i # => 42

# But if you might not have a number in your String, you should rather 
# use this instead, as to_i doesn't throw an Error:

"42test123".to_i # => 42
Integer("42test123") # => ArgumentError
Integer("42") # => 42
Posted by: Guest on June-17-2020

Browse Popular Code Answers by Language