- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to round the decimal number to the nearest tenth in JavaScript?
To round the decimal number to the nearest tenth, use toFixed(1) in JavaScript. The syntax is as follows −
var anyVaribleName=yourVariableName.toFixed(1)
Let’s say the following is our decimal number −
var decimalValue =200.432144444555; console.log("Actual value="+decimalValue)
Let’s now round the decimal number. Following is the code −
Example
var decimalValue =200.432144444555; console.log("Actual value="+decimalValue) var modifiedValue=decimalValue.toFixed(1) console.log("Modified value="+ modifiedValue);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo38.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo38.js Actual value=200.432144444555 Modified value=200.4
Advertisements