Hi folks I have the following code in my program. The aim is to generate a sense of time, like 1.01, 1.02.. 1.60 ,2.01 etc..
This gives me some strange errors like : 1.16 1.17 1.1800001 1.19 1.2 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.3 1.31 1.3199999 1.33 Any idea why this is happening ?? [This message has been edited by Maky (edited December 21, 2001).]
Hi Maky, It is called round-off error. Anytime you are printing float or double values you should format the results if it is important to you. Look at: java.text.DecimalFormat For example: DecimalFormat df = new DecimalFormat( "#.00" ); System.out.prnitln( df.format( y ) ); will make your output look consistent. Regards, Manfred.
Hi Maky, Surely we have had this talk before - but can you PLEASE re-register with a name that fits the JavaRanch's naming policy. Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name. Thanks, Cindy
"JavaRanch, where the deer and the Certified play" - David O'Meara