> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/c/convert_decimal_number_to_rational.md).

# Convert decimal number to rational

By default, literal numbers are represented in rational form:

```ruby
say 0.75.as_frac          #=> 3/4
say 0.518518.as_frac      #=> 259259/500000
say 0.9054054.as_frac     #=> 4527027/5000000
```

Additionally, `Num(str)` can be used for parsing a decimal expansion into rational form:

```ruby
'0.9054054 0.518518 0.75'.split.each { |str|
    say Num(str).as_frac
}
```

#### Output:

```
4527027/5000000
259259/500000
3/4
```

For rational approximations, the Number `.rat_approx` method can be used:

```ruby
say 0.518518.rat_approx.as_frac    #=> 14/27
say 0.9054054.rat_approx.as_frac   #=> 67/74
```
