Javascript number type, javascript number
Javascript numeric type
There is only one Number type in js, which is called all numbers in Number. js. This type includes integers 1,-2, 3, floating point number 1.1,-1.2, and 1.3. Therefore, in js, both the typof integer and the typof floating point return number.
JS type conversion
Js has three common functions used to convert non-numeric to numeric, namely, Number (), parseInt, and parseFloat (). They can be called directly in the window scope. Usage:
ANumber = Number (notNumber );
AInt = parseInt (notNumber );
AFloat = parseFloat (notNumber );
From the function name, we can see the function's role:
Number (): You can convert a non-Number to a Number. The conversion result may be an integer or a floating point Number.
ParseInt (): converts a non-numeric type to a number. The conversion result is an integer, which is directly rounded up without rounding.
ParseFloat (): converts a non-numeric type to a numeric type. The conversion result is a floating point number.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.