Get to know MDN better
Esta página ha sido traducida del inglés por la comunidad. Aprende más y únete a la comunidad de MDN Web Docs.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julio de 2015.
El método toPrecision() devuelve una cadena que representa un objeto Number según la precisión especificada.
Opcional. Un entero que especifica el número de digitos significativos.
Una cadena que representa un objeto Number en punto fijo o en notación exponencial redondeada a precision de digitos significativos. Vea la discusión acerca del redondeo en la descripción del método Number.prototype.toFixed() , que además aplica a toPrecision().
Si el parámetro precision es omitido, se comporta como Number.prototype.toString(). Si el parámetro precision es un valor no entero, el valor es redondeado al entero más cercano.
If precision is not between 1 and 100 (inclusive), a RangeError 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.
| ECMAScript® 2027 Language Specification # sec-number.prototype.toprecision |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 11 feb 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.