Js's method of rounding to retain one decimal place
This article introduces the relevant knowledge of "js rounding to retain a decimal place". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Use the Math.Round () function to get the rounded integer part, and then divide it by 10.
Var number = 0.409 flagship alert (Math.round (number * 10) / 10)
Output
0.4
2. Use the toFixed () method to round Number to a number that specifies one decimal place.
Let data=12.135;console.log (data.toFixed (1))
Output
12.1 this is the end of the content of "js rounding to retain one decimal place". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!