yagmurdursun - 8 months ago 27

Ruby Question

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

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
```