Fixed number of digits after the decimal place Using Javascript Example
Hi Guys
In this example, i will exmplain how to fixed number of digits after the decimal place using javascript. we will show javascript fuction using digits after the decimal place.Javascript has the toFixed() method to have a specific number of digits after the decimal place.
Here the example of digits after the decimal place Using Javascript.
Example using toFixed()
Now In this example,The toFixed() method converts a number into a string, rounding to a specified number of decimals.Convert a number into a string, rounding the number to keep only two decimals
document.write( 1.1.toFixed(2) + '<br>');
document.write( 2.12.toFixed(2) + '<br>');
document.write( 3.123.toFixed(2) + '<br>' );
document.write( 4.125.toFixed(2) + '<br>' );
document.write( 5.125.toFixed(4) + '<br>' );
output
1.10
2.12
3.12
4.13
5.1250
It will help you...
- How to set Date in setUTCHours() Method in JavaScript?
- How to Date sets UTC milliseconds in Javascript?
- How to Use push(), unshift(),pop() and shift() With Array in Javascript?
- How to Check if a Variable is a Number in Javascript?
- How To Format a Number Using Fixed - Point Notation in Javascript?
- How to Insert an Element into an Array in javaScript?
- How to remove duplicate elements from JavaScript Array?
- How to calculate years, months and days between two dates in javascript?