TypeScript: error when using parseInt() on a number

前端 未结 7 1140
心在旅途
心在旅途 2021-02-18 15:47

The JavaScript function parseInt can be used to force conversion of a given parameter to an integer, whether that parameter is a string, float number, number, etc.

7条回答
  •  無奈伤痛
    2021-02-18 16:01

    Don't use parseInt to do this operation -- use Math.floor.

    Using parseInt to floor a number is not always going to yield correct results. parseInt(4e21) returns 4, not 4e21. parseInt(-0) returns 0, not -0.

提交回复
热议问题