In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to convert JavaScript into numerical types, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Convert to a numeric type
(1), Number () can convert any value to a numeric value. If there is a character in the string that is not a numeric value, return NaN.
Such as:
Var num1 = Number ("10"); console.log (num1); / / 10var num2 = Number ('10adbdn'); console.log (num2); / / NaNvar num3 = Number ("10.78"); console.log (num3); / / 10.78var num4 = Number (' 10.65dd'); console.log (num4); / / NaNvar num5 = Number ("A10"); console.log (num5); / / NaN
(2), parseInt () to integer
Such as:
Var num1 = parseInt ("10"); console.log (num1); / / 10var num2 = parseInt ('10adbdn'); console.log (num2); / / 10var num3 = parseInt ("10.78"); console.log (num3); / / 10var num4 = parseInt (' 10.65dd'); console.log (num4); / / 10var num5 = parseInt ("A10"); console.log (num5); / / NaN
(3), parseFloat () to decimal
Such as:
Var num1 = parseFloat ("10"); console.log (num1); / / 10var num2 = parseFloat ('10adbdn'); console.log (num2); / / 10var num3 = parseFloat ("10.78"); console.log (num3); / / 10var num4 = parseFloat (' 10.65dd'); console.log (num4); / / 10var num5 = parseFloat ("A10"); console.log (num5)
The difference among (4), Number (), parseInt () and parseFloat ()
Number () is stricter than parseInt () and parseFloat ().
ParseInt () is similar to parseFloat (), and parseFloat parses the first one. I met the second one. Or a non-digital end.
What can JavaScript do? It can make web pages interactive, such as responding to user clicks and providing users with a better experience. two。 You can process forms, verify user input, and provide timely feedback to save users time. 3. The page can be created dynamically according to the user's operation. 4 using JavaScript, you can set up some temporary information that cookie stores on the browser.
The above is all the content of the article "how to convert JavaScript to numerical types". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.