filmov
tv
Convert numeric Strings into integer, float, double values using parse method
![preview_player](https://i.ytimg.com/vi/YvNsswXJMEM/maxresdefault.jpg)
Показать описание
Convert numeric Strings into integer, float, double values using parse method
In this video, I would like to show you how to convert Numeric Strings into actual numbers.
By definition, a numeric string is a String value consisting of only an Integer or a decimal number. For example these Strings on the screen are all made up of only integer or decimal numbers String str1 = “-100”; String str2 = “140.50”; or String str3 = “28.69”;
If you try to run arithmetic operations on these variables, you will not get the expected result.
Because these are actually Strings, the plus + symbol between them is considered as a concatenation operator but not an addition operator. Using the other arithmetic operators on these variables will result in an error.
So, in Java we can use special methods to convert these numeric Strings into actual numbers of type Integer, floating-point or Double; so that we can be able to perform arithmetic operations on them
Since that method will return an integer, I then need to declare an integer variable and call the method
Now, if I perform an arithmetic operation on this value, it will work
In the second example, I am going to convert into a value of type Double. So, I will follow the same logic
Finally, in the last example I am going to convert into a value of type Float
Now, you can freely perform arithmetic operations on these converted values, as you wish.
Thanks for viewing, I hope this video was informative and please do not forget to Subscribe to this channel for more
In this video, I would like to show you how to convert Numeric Strings into actual numbers.
By definition, a numeric string is a String value consisting of only an Integer or a decimal number. For example these Strings on the screen are all made up of only integer or decimal numbers String str1 = “-100”; String str2 = “140.50”; or String str3 = “28.69”;
If you try to run arithmetic operations on these variables, you will not get the expected result.
Because these are actually Strings, the plus + symbol between them is considered as a concatenation operator but not an addition operator. Using the other arithmetic operators on these variables will result in an error.
So, in Java we can use special methods to convert these numeric Strings into actual numbers of type Integer, floating-point or Double; so that we can be able to perform arithmetic operations on them
Since that method will return an integer, I then need to declare an integer variable and call the method
Now, if I perform an arithmetic operation on this value, it will work
In the second example, I am going to convert into a value of type Double. So, I will follow the same logic
Finally, in the last example I am going to convert into a value of type Float
Now, you can freely perform arithmetic operations on these converted values, as you wish.
Thanks for viewing, I hope this video was informative and please do not forget to Subscribe to this channel for more