This post will describe the methods to round down the number to one decimal place in JavaScript.
How to Round to 1 Decimal Place/Value Using JavaScript?
For rounding the number to the 1 decimal place, use the below-given methods:
Method 1: Round to 1 Decimal Place/value Using “Math.round()” Method
Use the “Math.round()” method which rounds a number to the nearest/closest integer value. For rounding the number to the 1 decimal place, first multiply the number by 10, round it to the nearest integer using Math.round(), and then divide the result by 10.
Syntax
For rounding a number to 1 decimal place, use the given syntax:
Example
Create a variable that stores a decimal number “15.89345”:
Round the number using the Math.round() method:
Finally, print the result on the console:
The number is successfully rounded to the 1 decimal place:
You can also pass the number directly to the Math.round() method as follows:
Output
Method 2: Round to 1 Decimal Place/Value Using “toFixed()” Method
Another way for rounding the number to 1 decimal place is the “toFixed()” method. It rounds the number to the specified number of decimal points. For rounding a number to 1 decimal place utilizing toFixed(), specify “1” as the argument to the method.
Syntax
The following syntax is utilized for the toFixed() method:
Example
Call the toFixed() method on the number by passing “1”, which indicates that round the number to the 1 decimal place:
The output indicates that the number 15.89345 has been successfully rounded to the 1 decimal place:
You can also use this method as follows:
Output
That’s all about rounding a number to the 1 decimal place in JavaScript.
Conclusion
To round the number to the 1 decimal place, use the “Math.round()” method or the “tofixed()” method. To round a number to 1 decimal place using Math.round() method, first, multiply the number by 10, round it to the nearest integer value using Math.round(), and then divide the result by 10. While using the toFixed(), specify “1” as the argument to the method. This post described the methods for rounding the number to one decimal place.