How to integer javascript without decimals
This article is to share with you about how javascript does not have decimals. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Methods: 1, rounding with "parseInt" sentence, 2, rounding with "numerical .tofixed (0)" sentence, 3, rounding with "Math.ceil" sentence, 4, rounding with "Math.floor" sentence, 5, rounding with "Math.round" sentence, etc.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In javascript, a number can be rounded if it does not want the decimal part (decimal part removed). Here are some methods of javascript rounding.
The method of how to round up javascript (not decimal)
1. ParseInt ()
/ / js built-in function, note that the accepted parameter is string, so there is a type conversion parseInt (1.5555) / / = > 1 when the method is called
2. Number.toFixed (0)
/ / Note the string returned by toFixed. If you want to get an integer, you need to do type conversion 1.5555.toFixed (0) / / = > "1".
3. Math.ceil ()
/ / rounding up Math.ceil (1.5555) / / = > 2
4. Math.floor ()
/ / rounding down Math.floor (1.5555) / / = > 1
5. Math.round ()
/ / rounding Math.round (1.5555) / / = > 2Math.round (1.4999) / / = > 1
6. Math.trunc ()
/ / discarding decimal rounding Math.trunc (1.5555) / / = > 1
7. Double bit non-rounding
/ / rounding using bit operation. Only 32-bit signed integers are supported. Decimal places will be discarded. Same as ~ 1.5555 / / > 1 below.
8. To transport or round up by bit.
1.5555 | 0 / / = > 1
9. Bitwise XOR rounding
1.5555 ^ 0 / / = > 1 Thank you for reading! This is the end of the article on "how to do not decimal javascript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!