yagmurdursun yagmurdursun - 1 year ago 65
Ruby Question

get fraction part of a decimal number

I am trying to get a fraction part of a decimal number in rails. For example I have a number, that "1.23" and I want to get "23" It is may be too easy but, does anyone have any idea about how can I do?

Answer Source

I am not sure if it is the easiest way to do it - but you can simply split the number using "." character - like this:

number = 1.23
parts = number.to_s.split(".")
result = parts.count > 1 ? parts[1].to_s : 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download