Can we compare a double value... double d = 999.99; if(d==999.99) { } Or should we comvert the double to string, Double dd=new Double(999.99); String str="9999999.99"; if(str.equalsIgnoreCase(dd.toString())) { } Which way is correct?
The problem with doubles and floats is that there is always this rounding issue with them. Therefore you can never COUNT on the value of the double being what you think it should be. Try reading this: http://www.javaranch.com/ubb/Forum1/HTML/000525.html
"JavaRanch, where the deer and the Certified play" - David O'Meara
Hi, I need to check the input value is exact 999.99 or not. So there no change in this value. So can chack the incomming value aganist this hard coded value as I discribled above? Thanks
Hi,Bala Krisna U can compare this as follows class Test1{ void testDouble(){ double d=999.99; double dd = 999.99; // or //U can get a value by input and change it to double //check with API Double methods. if(d==999.99) System.out.println("I am equal and double value"); else System.out.println(" I am not equal"); } public static void main(String[]args){ Test1 t= new Test1(); t.testDouble(); } } regrds vkswami