View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
pol pol is offline
external usenet poster
 
Posts: 129
Default Wrong result is coming while adding tow figures

Now it is working fine


"Bernard Liengme" wrote:

The problem has to do with computers way of converting digital numbers
(number using base 10) to binary (base 2) and is a well known problem - see
sites below. I am not sure what JLatham mean by "analog".
Excel (and most other apps) store number with 15 digit precision,

To avoid this: suppose your formula is =A1+A2, replace this by
=ROUND(A1+A2,10)
The 10 could be another value such as 6 or 12, depending on the precision of
you work
best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme


Chip's clear explanation
http://www.cpearson.com/excel/rounding.htm

Floating-point arithmetic may give inaccurate results in Excel
http://support.microsoft.com/kb/78113/en-us

(Complete) Tutorial to Understand IEEE Floating-Point Errors
http://support.microsoft.com/kb/42980

What Every Computer Scientist Should Know About Floating Point
http://docs.sun.com/source/806-3568/ncg_goldberg.html
http://www.cpearson.com/excel/rounding.htm

Visual Basic and Arithmetic Precision
http://support.microsoft.com/default...NoWebContent=1

Others:
http://support.microsoft.com/kb/214118

http://docs.sun.com/source/806-3568/ncg_goldberg.html
Go to source web page


"pol" wrote in message
...
Hi all,
I wrote the following function . But in some time the result is showing
wrong format. When VarSum gets value 185.42 and ValueSum gets -185.42 the
result should be 0.

VarSum = VarSum + ValueSum
0= 185 + - 185 . But some cases Excel shows the balance as
8.5265128E-14.

Please help. I given the function below.

Sub CashBookMacrosnew()
Dim VarSum As Double
Dim ValueSum As Double
Dim VarSumOld As Double
Dim totalsum As Double

lastrow = Range("B" & Rows.Count).End(xlUp).Row
currow = ActiveCell.Row
pre_row = ActiveCell.Row
Col_A = ""

For RowCount = 1 To lastrow
If RowCount 1 Then
pre_row = RowCount - 1
If Range("A" & RowCount) < "" Then
VarSumOld = VarSum
VarSum = Range("R" & RowCount)
Range("Y" & pre_row) = VarSumOld
Else

ValueSum = (Range("R" & RowCount) + Range("S" & RowCount) + Range("T" &
RowCount) + _
Range("U" & RowCount) + Range("V" & RowCount) + Range("W" & RowCount) +
_
Range("X" & RowCount))
VarSum = VarSum + ValueSum
End If
End If


Next RowCount

End Sub

.