Here you will learn how to convert a Numer String to different number types.
Each number type in Java has a parse method that allows you convert a string into the primitive type.

When converting a string to a number, the parse method may throw a NumberFormatException if the string is null or an invalid representation for that type.

Ok now why am I showing you this? let’s say you are pulling data from your DB but want to preform calculations on the values, unfortunately the number in the Strings are not ment to be final values and will give you odd numbers for calculations.
Please keep this in mind and take into consideration that an “int” and a “long” will only give you the full number and not the decimal point.

Convert a String to an int

To convert a String to an int, call the static method parseInt() on the Integer class. Below is an example:


String string = "123";
int value = Integer.parseInt(string);

Convert a String to a long
To convert a String to a long, call the static method parseLong() on the Long class. Below is an example:

String string = "123";
long value = Long.parseLong(string);

Convert a String to a float
To convert a String to a float, call the static method parseFloat() on the Float class. Below is an example:

String string = "123.4";
float value = Float.parseFloat(string);

 

Convert a String to a double
To convert a String to a double, call the static method parseDouble() on the Double class. Below is an example:

String string = "123.4";
double value = Double.parseDouble(string);
Here is an example from my code that shows a quick calculation of some sort
// Convert The060 String to Float for Calculations
float The060f = Float.parseFloat(The060);
int eight = 8;
int ten = 10;
int six = 6;</div>
<div>String TheVerdict = "";</div>
<div>

// Do Some Calculations
if (The060f &lt; six) {
TheVerdict = "It's One Amazing Ride!";
} else if (The060f &lt; eight &amp;&amp; The060f &gt; six) {
TheVerdict = "It's One Great Ride!";
} else if (The060f &lt; ten &amp;&amp; The060f &gt; eight) {
TheVerdict = "It's a Decent Ride....";
} else if (The060f &gt; ten) {
TheVerdict = "IT SUCKS!";
}

// Show AlertDialot with Monkey Thoughts
new AlertDialog.Builder( this )