Hey all ,
Please run the below program and see the output you get. It gives the output as 1.2 when i change the parameter in the place of 1.2 as 1.1.Similarly it gives 1.4 when i enter 1.3 in place of 1.2. It works for al inputs but when I enter 1.2 it outputs 1.300001. Why is it so?
Code:
public class test1 {
public static void main(String[] args) {
float existVersion = Float.parseFloat("1.2");
float NewVersion = (float) (existVersion + 0.1);
String newVersion=String.valueOf(NewVersion);
System.out.println(newVersion);
}
}
Bookmarks