hello java forum,
Good Morning.
Here i came up with a mess about a program.
Iam not obtaining a accurate result .
But , in C the program is giving an accurate result.
in java , the program goes like this
public class FloatingNumber {
public static void main(String...args) {
double i;
double num=0.0;
for(i=0.0;i<10;i++)
num=num+0.1;
System.out.println(num);
}
}
// output =0.9999999999999999
// In C the program goes like this
#include<stdio.h>
#include<math.h>
main()
{
double i, num=0.0;
for(i=0;i<10;i++)
num=num+0.1;
printf("%f",num);
}
// output =1.00000
please explain me the difference and resolve my problem.
Thanks in advance