In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "how to turn a string into a number in java", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to turn a string into a number in java" can help you solve your doubts.
Method 1:
Integer.parseInt ():
This method, we are through the character type of a number into an integer process, let's look at the code and run a result!
Package Change;public class TrunChange {public static void main (String [] args) {String s = "0000012342"; int a = Integer.parseInt (s); System.out.println ("before the string is:" + s); System.out.println ("the converted number is:" + a);}}
As we can see in the results, the string before conversion is different from the comparison after conversion. And the usage of Integer.valueOf () is the same.
Method 2:
Float.parseFloat ():
If we use this method, we convert a numeric string into a floating-point number, the code and the result are as follows:
Package Change;public class TrunChange {public static void main (String [] args) {String s = "0000012342"; float b=Float.parseFloat (s); System.out.println ("before the string is:" + s); System.out.println ("the converted number is:" + b);}}
The number shown in this result is followed by a decimal point, which shows that our results are correct.
After reading this, the article "how to turn a string into a number in java" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, please 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
Simply lay the groundwork and look at it first.
© 2024 shulou.com SLNews company. All rights reserved.