Unwanted rounding in a sum !!!!!
-
Ok this is something :mad::mad::mad::mad::mad::mad::mad: The problem I have is that when I'm calculating some values the sum is rounded and i dont want it for example, here is some of my code ******************** code ******************* dim price, totalprice, tax as Long Format TotalPrice, "$#,##0;;\Z\e\r\o" Format Tax, "$#,##0;;\Z\e\r\o" Format Price, "$#,##0;;\Z\e\r\o" Price = 0 For i = 0 To 21 Price = Price + LBLSelPrice(i).Caption Next LblTotal.Caption = Price ' eg 125 Tax = (Price * 0.18) LblTax.Caption = Tax 'equals 22.5, displays fine TotalPrice = Tax + Price LblGenTotal = TotalPrice ' Here it displays 148 instead of 147.50 *********************** code ****************** while debugging I noticed that the problem is not the labels problem but I was watching my variables and I saw that the totalprice var. when I am summarizing the price and the tax vars is rounded. In the labels properties I changed the format to number with 2 decimal points !!! It s not workink, no way !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :mad::mad::mad::mad::mad::mad: HELP !!! Mike Eco
-
Ok this is something :mad::mad::mad::mad::mad::mad::mad: The problem I have is that when I'm calculating some values the sum is rounded and i dont want it for example, here is some of my code ******************** code ******************* dim price, totalprice, tax as Long Format TotalPrice, "$#,##0;;\Z\e\r\o" Format Tax, "$#,##0;;\Z\e\r\o" Format Price, "$#,##0;;\Z\e\r\o" Price = 0 For i = 0 To 21 Price = Price + LBLSelPrice(i).Caption Next LblTotal.Caption = Price ' eg 125 Tax = (Price * 0.18) LblTax.Caption = Tax 'equals 22.5, displays fine TotalPrice = Tax + Price LblGenTotal = TotalPrice ' Here it displays 148 instead of 147.50 *********************** code ****************** while debugging I noticed that the problem is not the labels problem but I was watching my variables and I saw that the totalprice var. when I am summarizing the price and the tax vars is rounded. In the labels properties I changed the format to number with 2 decimal points !!! It s not workink, no way !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :mad::mad::mad::mad::mad::mad: HELP !!! Mike Eco
Variables declared as Long cannot hold fractional parts, and will always be rounded.
Dim Price As Currency, TotalPrice As Currency, Tax as Currency, i As Long
Price = 0
For i = 0 To 21
Price = Price + CCur(LBLSelPrice(i).Caption)
Next
LblTotal.Caption = Price
Tax = (Price * 0.18)
LblTax.Caption = Tax
TotalPrice = Tax + Price
LblGenTotal.Caption = TotalPrice
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer