Comparing Two decimal nos. for equality in vb.net

In a Financial Accounting program, I accept individual accounting entries some of them are debit and some are credit. Finally, for each voucher Debit must be = Credit.

I do the following:

Dim decTotdr As Decimal = 0
Dim decTotcr As Decimal = 0
Dim int I As Integer = 0
Dim intentries As Integer = 0

for intI = 0 to intentries -1

if Me.txtDrcr.Text = 'DR' then
decTotdr = decTotdr + Ctype(Me.txtVoucheramt.Text,Decimal)
else
decTotcr = decTotcr + Ctype(Me.txtVoucheramt.Text,Decimal)
endif

next intI

if Math.Abs(decTotdr - decTotcr) >= 0.01 then

MessageBox.Show("Debit <> Credit")
exit sub

endif

It works most of the time. But sometimes it gives an error, e.g. Debit 500 <> Credit 500.

Is there a better way to do this comparison?

Dilip Nagle


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories