hi,
when i try to multiply the double value with 100, i got inconsistent o/ps..
here the codes...
Case1:-
double d=15.025d;
System.out.println("d="+(d*100));
o/p:-d=1502.5

Case 2:-
double d=16.025d;
System.out.println("d="+(d*100));
o/p:-
d=1602.4999999999998
and this issue to 17.025,18.025,19.025 & 20.025 also.
it suppose to be d=1602.5 right?
why these particular o/p and how to fix this

This always happens with floating point values. There is no exact binary fraction that corresponds to decimal .025 so you get the nearest binary value, which is nearer to .024999
You can use a formatting method (eg printf) to display the result rounded to the right number of decimal places.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.