Jump to content

Table


sazzadhossain
 Share

Recommended Posts

Hi

I was trying to add up this column values. It is always showing 3.9999999 instead of 4. I was checking in many ways, and I found it is only the 8th row which gives me 0.2999999 instead of 0.3 . But if I put any other value instead 0.3 the summation is working . Only 0.3 value and it is only for the row number 8 I get this error value. However if I check the trace it has no problem. If I check it by a status level in the facility view it actually shows the values is 0.29999 . I changed my Simio version, nut still It is not working. I can't say my process is wrong as it works for any other value except 0.3. Pls note that 0.3 value for any other row is working fine.

what could be the reason.

Any suggestion will be much appreciated

Capture.JPG.6b4b08ddc2af7421cc5a6e79a3751f67.JPG

 

regards

Sazzad

Link to comment
Share on other sites

There is a very good reason, but probably not one you will like.


Most computer computations (and all those in Simio) are done in binary, which is simply summarized as all numbers, even fractions, are specified as powers of 2. All integers and many fractions (like 1/8th or 15/32nds) can be exactly represented in binary, but many decimal numbers cannot. The number 0.3 is one such number - it is represented in binary as something like 0.299999999999999.


When you represent numbers in double precision, as Simio does in most cases and then round it off to something most humans can relate to, it usually provides what humans expect to see. For example, if you display the above number rounded to say 8 significant digits, what you see is 3.0000000.


When these numbers are used in calculations, particularly when compared to integers you can get unexpected results. For example, depending on the exact circumstances, the expression "10 * 0.3 == 3" is likely to evaluate as false because it is not comparing the rounded numbers -- it may be comparing 2.999999999999999 to 3, which of course is false.


This problem is not in any way unique to Simio, it is found in most programs which manipulate decimals. In fact it occurs less in Simio because of the use of double precision.


A natural question may be, "How do banks deal with this?" In fact a common scam from decades ago was to collect such round off and funnel it into someone's pocket. It may sound small, but a few billion fractional cents can start to turn into real money. So they came up with a way of representing decimal numbers that does not have this representation or round off problem. Unfortunately this procedure is both big and slow and is not justified in most computationally intensive software like simulation.


So we must live with it. The bottom line: don't depend on a decimal number to be exact especially when compared to an integer.

Link to comment
Share on other sites

×
×
  • Create New...