Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Js's method of rounding to retain one decimal place

Shulou Source: shulou.com Published: 2022-05-31 10:38:45 10月04日 Update

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!

Tags: Rounding rounding decimal method output content more knowledge utility learning next digits functions dilemmas reality situations numbers integers articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi MySQL Shulou Information NVidia