w3schools
  
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

JavaScript toPrecision() Method


Number Object Reference JavaScript Number Object

Definition and Usage

The toPrecision() method formats a number to a specified length.

A decimal point and "0"s are added (if needed), to create the specified length.

Syntax

NumberObject.toPrecision(digits)

Parameter Description
digits Required. The number of digits


Example

Example

In this example we will change number of digits for a number:

<script type="text/javascript">

var num=13.3714;
document.write(num.toPrecision(1)+"<br />")
document.write(num.toPrecision(3)+"<br />")
document.write(num.toPrecision(10))

</script>

The output of the code above will be:


Try it yourself »


Number Object Reference JavaScript Number Object

DreamTemplate


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
Top Web Hosting
Windows Hosting
WEB BUILDING
XML Editor – Free Trial!
FREE Flash Website
FREE Web Templates
FLIGHT TICKETS
Find the cheapest flight
to any destination now!
EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
STATISTICS
Browser Statistics
Browser OS
Browser Display