int to float java code example

Example 1: convert string to float java

String yourString = "23.7";
float yourFloat = Float.parseFloat(yourString);

Example 2: java convert float to int

int a = (int)float1

Example 3: string to float java

String output = Float.parseFloat(floatNum); /** convert float to string using objName.parse(ObjName) <--capitalized usually. */

Example 4: what is a float java

float int = 3.1415 //pi is a float because it is a decimal

Example 5: float to int in java

Using Math.round() will round the float to the nearest integer.

Tags:

Java Example