Fixed number of digits after the decimal place Using Javascript Example

JavaScript

Nicesnippets

131

23-05-2020


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...