I call the following method to convert the inputs as indicated in the body :
public static double convertFromHectareAreCentiareToHectare(int hectare, int are, int centiare){
double d;
DecimalFormat df = new DecimalFormat("######.####");
d = Double.valueOf(df.format((hectare*10000+ are * 100 + centiare)/10000));
return d;
}
}
When I call this method with :
convertFromHectareAreCentiareToHectare(1, 90, 90)
I get : 1.0
But I should normally get 1.9090
What is the problem with my code ?
EDIT :
After changing 10000 to 10000.0, I got the following exception :
Exception in thread "main" java.lang.NumberFormatException: For input string: "1,909"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.valueOf(Unknown Source)
at ma.ancfcc.Utilities.Convert.convertFromHectareAreCentiareToHectare(Convert.java:21)
at ma.ancfcc.Utilities.Convert.main(Convert.java:8)