What is the proper way to deal with leading zeros in Ruby?
0112.to_s
=> "74"
0112.to_i
=> 74
Why is it converting 0112
into 74
?
How can convert 0112
to a string "0112"
?
I want to define a method that takes integer as a argument and returns it with its digits in descending order.
But this does not seem to work for me when I have leading zeros:
def descending_order(n)
n.to_s.reverse.to_i
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…