- TypeScript Tutorial
- TypeScript - Home
- TypeScript - Overview
- TypeScript - Environment Setup
- TypeScript - Basic Syntax
- TypeScript - Types
- TypeScript - Variables
- TypeScript - Operators
- TypeScript - Decision Making
- TypeScript - Loops
- TypeScript - Functions
- TypeScript - Numbers
- TypeScript - Strings
- TypeScript - Arrays
- TypeScript - Tuples
- TypeScript - Union
- TypeScript - Interfaces
- TypeScript - Classes
- TypeScript - Objects
- TypeScript - Namespaces
- TypeScript - Modules
- TypeScript - Ambients
- TypeScript Useful Resources
- TypeScript - Quick Guide
- TypeScript - Useful Resources
- TypeScript - Discussion
TypeScript - Number toPrecision()
This method returns a string representing the number object to the specified precision.
Syntax
number.toPrecision( [ precision ] )
Parameter Details
precision − An integer specifying the number of significant digits.
Return Value
Returns a string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.
Example
var num = new Number(7.123456); console.log(num.toPrecision()); console.log(num.toPrecision(1)); console.log(num.toPrecision(2));
On compiling, it will generate the same code in JavaScript.
The code will produce the following output −
7.123456 7 7.1
typescript_numbers.htm
Advertisements