In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.