Can you round a number in JavaScript to one character after the decimal point (properly rounded)?
I tried the *10, round, /10, but it leaves two decimals at the end of the int.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Math.round(num * 10) / 10works, and here is an example…If you want it to have one decimal place, even when that would be a 0, then add…
Using this principle, for reference, here is a handy little round function that takes precision…
… usage …
… defaults to round to nearest whole number (precision 0) …
… and can be used to round to nearest 10 or 100, etc…
… and correct handling of negative numbers …
… and can be combined with toFixed to format consistently as string …