Decimal places in Dlookup missing

lehcarrodan

Registered User.
Local time
Today, 12:03
Joined
Feb 20, 2017
Messages
11
Hi I have a Dlookup in my vba code that goes to my tblTaxes and puts the number into a text box on my form (it works! Sort of..). Problem is, in the table it shows the proper value 9.975% and in the text box it cuts the last decimal. Why's this happening?/@^@&!!! Even when I tell it to show more it gives 9.9700000 how can I fix this?

Thank you for any help/suggestions
 
Do y have ant formatting on the textbox?
 
IF the field is set to decimal (single or double) it will hold a lot of decimals, tho you may only see a few.
format() is the answer to view more.
 
IF the field is set to decimal (single or double) it will hold a lot of decimals, tho you may only see a few.
format() is the answer to view more.

I have set the field to double..
It now seems to be rounding up the value 9.975 to 9.98 and then showing more decimals 9.98000

Really not getting this and seems pretty basic lol

I use this to look up table value:
Me.txtPST = DLookup("PST", "tblTaxes", "Province = '" & Me.txtBillState & "'")

Table stores the right value 9.975
 
I had the same issue. What I found if you use Dsum Instead of Dlookup it works. Why Dlookup doesn't work it is a mystery.
 
Last edited:
it's a bit risky trying to test equality to a real number - ie with decimals, since many real numbers can't be completely represented in binary. Dlookup with a decimal number may fail to find a match because of tiny rounding errors.
 
It now seems to be rounding up the value 9.975 to 9.98 and then showing more decimals 9.98000

This tells me that there are at least two steps here and one of the steps involves rounding. If you were working entirely in SINGLE datatype and just rounded to three places, you should get what you wanted. The fact that you didn't means that something else is in the picture that you haven't told us about, or that you have not realized.

Computers are predictable when it comes to math. (If they weren't we would have abandoned them decades ago.) SINGLE datatype math is capable of handling your problem. So ... where do you introduce something that ISN'T a SINGLE datatype?
 

Users who are viewing this thread

Back
Top Bottom