Okay a bit over dramatic start but i have a huge maths issue in computing !. Not language specific but how the computer chose to calculate the following sum
int ((82.82 + 77.77) * 100)
The answer should be 16059... But it isn't, its 16058. For the sake of my sanity help!...
Sample code...
import java.io.*;
class CastTest
{
public static void main (String args[])
{
System.out.println("Test");
double Val3=82.82;
double Val4=77.77;
int Val1=(int)((Val3+Val4)*100);
System.out.println(Val1);
}
}
TiG


LinkBack URL
About LinkBacks
Reply With Quote


) IEEE Standard 754 Floating-Point. As someone said the nearest you can store the number isn't what you think it is, ie this code might not behave how you'd think