An invalid results from a simple calc It's code: while not rs.eof wvl_lanc_atu_tro = rs("vl_lancamento") response.write "<br>*** Start Calc ***" response.write "<br>From: " & wvl_saldo_tro_atu & " Plus: " & wvl_lanc_atu_tro wvl_saldo_tro_atu = wvl_saldo_tro_atu wvl_saldo_tro_atu = wvl_saldo_tro_atu + wvl_lanc_atu_tro response.write "<br>New result: " & wvl_saldo_tro_atu response.write "<br>Result to write: " & wvl_saldo_tro_atu response.write "<br><br>" rs.fields("vl_saldo") = wvl_saldo_tro_atu rs.update rs.movenext wend Processing: *** Start Calc *** From: 0 Plus: 0,31 New result: 0,31 Result to write: 0,31 *** Start Calc *** From: 0,31 Plus: 92,78 New result: 93,09 Result to write: 93,09 *** Start Calc *** From: 93,09 Plus: -96,39 New result: -3,300003 Result to write: -3,300003 ===> Correct is 3,3 *** Start Calc *** From: -3,300003 Plus: 1,25 New result: -2,050003 Result to write: -2,050003 *** Start Calc *** From: -2,050003 Plus: 0,05 New result: -2,000003 Result to write: -2,000003 *** Start Calc *** From: -2,000003 Plus: 2 New result: -3,099442E-06 Result to write: -3,099442E-06 What is happening???????
try adding the highlighted line: while not rs.eof wvl_lanc_atu_tro = rs("vl_lancamento") response.write "<br>*** Start Calc ***" response.write "<br>From: " & wvl_saldo_tro_atu & " Plus: " & wvl_lanc_atu_tro wvl_saldo_tro_atu = wvl_saldo_tro_atu wvl_saldo_tro_atu = wvl_saldo_tro_atu + wvl_lanc_atu_tro [B][COLOR="Red"]wvl_saldo_tro_atu = FormatNumber(wvl_saldo_tro_atu, 2)[/COLOR][/B] response.write "<br>New result: " & wvl_saldo_tro_atu response.write "<br>Result to write: " & wvl_saldo_tro_atu response.write "<br><br>" rs.fields("vl_saldo") = wvl_saldo_tro_atu rs.update rs.movenext wend Code (markup):
The problem is not ROUND. Operation: wvl_saldo_tro_atu = 93.09 wvl_lanc_atu_tro = -96.39 instruction: wvl_saldo_tro_atu = wvl_saldo_tro_atu + wvl_lanc_atu_tro Then 93.09 + (-96.39) = -3.3 but result is -3.300003 93.09 - 96.39 = 3.3 The result 3.300003 is impossible.It's an error, not round problem. Only with some values the problem ocours. Database is Ok, I think. The problem occurs before update DB. If you want to download DB and ASP source code to test yourself: conectafarma.com/cf/downloads/DBtest.zip I'm running in IIS 5.1, but in others servers the problem persists. Please Help!!!!
Hi, Looking at the files you provided me the problem is within the database... Your fields: vl_lancamento AND vl_saldo ... are of set to type 'Single', and decimal places Auto (which must round to 2)... Go into design view of the table and change the 'Field Size' of these fields to 'Double'.... Now view the contents of your table: the first is : 0.310000002384186 second is: 92.7799987792969 etc. etc. This is what is causing the problem... either change the values of the table or round the values as you calculate.