fardin fardin - 2 years ago 73
Ruby Question

How to turn float decimal values into integers in ruby

How can one get the decimal values of a float and turn it into an integer in ruby?

Here is how far I got so far:

number = 12.55
decimal_length = number.to_s.split('.')[1].size #=> 2
decimal = number.divmod(1)[1].round(decimal_length) #=> 0.55

Here how can I turn decimal into integer (55) in a way that it would work with any number as input?

Answer Source

Maybe I'm misunderstanding? But you've got it you're just doing extra work.

number = 12.55
#  => 55 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download