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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/c/convert_decimal_number_to_rational.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
