How do I round a number in JavaScript?

后端 未结 8 2168
余生分开走
余生分开走 2020-11-27 03:20

While working on a project, I came across a JS-script created by a former employee that basically creates a report in the form of

Name : Value
Name2 : Value2         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 04:13

    You can use Math.round() for rounding numbers to the nearest integer.

    Math.round(532.24) => 532
    

    Also, you can use parseInt() and parseFloat() to cast a variable to a certain type, in this case integer and floating point.

提交回复
热议问题