---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Number.prototype.toPrecision()

The **`toPrecision()`** method returns a string representing
the `Number` object to the specified precision.

## Syntax

```js
toPrecision()
toPrecision(precision)
```

### Parameters

- `precision` _**optional**_
  - : An integer specifying the number of significant digits.

### Return value

A string representing a `Number` object in fixed-point or exponential
notation rounded to `precision` significant digits. See the discussion of
rounding in the description of the [`Number.prototype.toFixed()`](../../../globals/Number/prototype/toFixed.mdx) method,
which also applies to `toPrecision()`.

If the `precision` argument is omitted, behaves as
[`Number.prototype.toString()`](../../../globals/Number/prototype/toString.mdx). If the `precision` argument is a
non-integer value, it is rounded to the nearest integer.

### Exceptions

- `RangeError`
  - : If `precision` is not between `1` and `100`
    (inclusive), a [`RangeError`](../../../globals/RangeError/RangeError.mdx) is thrown. Implementations are allowed to
    support larger and smaller values as well. ECMA-262 only requires a precision of up to
    21 significant digits.
