double and float value in java
I am new to java and using it for numerical calculations............
Earlier I thought JAVA is great because of OOPs and it is advance than C or C++ ...........
But recently I got the problem regarding the double values . For example this code ..
It should print 5.03 but it prints 5.029999999999999
double x = 5.02;
double y = 0.01;
double z = x + y;
This is nonsense ........... :eek: :eek: :eek: :eek:
I have already written few codes in JAVA and now i think all my effort is just a waste, because like C i declared every variable as double, and in my calculation 0.0 and 5.029999999999999 are two different things and I need the accurate value.
What should I do ??????
What is the easy and accurate way ?? Should i stop using java or there is any way out ............ :confused: