/ Published in: Java
this programming shows you the example of floating point rounded off error. this error usually happen when you calculate numbers which has long decimal places or so on.
Expand |
Embed | Plain Text
/* Give an example of a floating-point roundoff error. Would the same expample work corrextly if you used int and awitched to a fuggiciebtly small unit, such as cents insted of dollars, so that the value don't have a fractional part? */ public class floatingPoint { public double number1; public double number2; public floatingPoint() { number1 = 23.30; number2 = 13.21; } { floatingPoint sample = new floatingPoint(); double amount = ((sample.number1 + (sample.number2*0.30))/45); System.out.println("Because, as I show, this number should continue to infinity digits of decimal places however, Java compiler automatically rounded up by 16th place."); } }
You need to login to post a comment.
