# Getting the number of decimal places

```ruby
func number_of_decimals(n, limit = 1e5) {
    var prec = Num(Num!PREC)>>2
    var prev = ''

    n = Number(n) if !n.kind_of(Number)

    loop {
        var str = n.as_dec(prec)

        if (prev == str) {
            return (str.contains('.') ? str.substr(str.index('.')+1).len : 0)
        }

        prev = str
        prec *= 2
        return Inf if (prec > limit)
    }
}

var list = [
    9, 12.345, "12.3450", "12.345e53",
    12.34555555555555555555, 0.1234567890987654321,
    Num.pi, 1/3, 1.5**63
]

list.each {|n|
    var c = number_of_decimals(n)
    say "Number of decimals: #{'%3s' % c}  Number: #{n}"
}
```

#### Output:

```
Number of decimals:   0  Number: 9
Number of decimals:   3  Number: 12.345
Number of decimals:   3  Number: 12.3450
Number of decimals:   0  Number: 12.345e53
Number of decimals:  20  Number: 12.34555555555555555555
Number of decimals:  19  Number: 0.1234567890987654321
Number of decimals: 188  Number: 3.14159265358979323846264338327950288419716939938
Number of decimals: Inf  Number: 0.333333333333333333333333333333333333333333333333
Number of decimals:  63  Number: 124093581919.6489476978273736503801880082242803382541751489
```


---

# 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/g/getting_the_number_of_decimal_places.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.
