Bert-Jan Brinkhuis
thevigil at kabelfoon.nl
Thu Mar 18 14:14:20 CST 2004
Gustav, thanks for your answer. I keep forgetting textboxes only contain text... i think i will forget it this time again... ;-) The maximum is 2 decimals so that is no problem. But since the differences was at the 15th decimal (although i only tested this 1 time...) I decide to add round([calculation];2) in the total field. I think this is ok because i know only numers with 2 decimals are entered.... Bert-Jan ----- Original Message ----- From: "Gustav Brock" <gustav at cactus.dk> To: "Access Developers discussion and problem solving" <accessd at databaseadvisors.com> Sent: Thursday, March 18, 2004 11:18 AM Subject: Re: [AccessD] Strange results with simple calculation on a form > Hi Bert-Jan > > Welcome back. > > Unbound textboxes contain text no matter how you format them. > And decimals may not be exact Doubles and indeed not Singles. > > If you can accept a maximum of four decimals, use CCur(txtYourTextbox) > to convert to Currency before doing any calculation or comparison. > Else use CDbl() and compare to a max. tolerance of your choice: > > If Abs(dblTotal - dblAmount) < 1E-7 Then > ' Values are equal. > End If > > /gustav > > > > Hi all, > > > i was forced to unsubscribe a while ago because i couldn't keep up with you > > and all the messages... ;-) > > > But today a strange thing happened i had to ask you all about. I didn't do a > > big search on the internet, but searched the accessd archives and didn't > > find it. It maybe is a well known problem, but here it goes..... > > > I have an unbound form where users will type amounts. All the txtboxes' > > format are set to "standard" and the decimal places is set to 2. And i check > > on the before_update event of these txtboxes if there are more then 2 > > decimals, if so, cancel = true. There is an calculated total control > > (txtTotal) wich has a controlsource like =[txtbox1]+[txtbox2] and so on (in > > total 12 txtboxes) > > These txtboxes are used to 'split up' the amount in another txtbox. > > (txtAmount) > > > Before saving i check if txtAmount = txtTotal. When no decimals are used > > there is no problem, if there are only used decimals in 1 txtbox there is no > > problem. But if there are used decimals in more txtboxes access will tell me > > the values are not the same..... although the same values are shown... it > > turns out there is a difference of: 0.00000000000000710542735!!!!!! > > (debug.print told me this!) > > > When i use the same 'function' in VBA it works fine with the same > > values....???? > > > So it is not a real problem, but it IS something strange... wel to me it > > is.... > > > Thanks in advance. > > > Hope to keep up with you this time... ;-) > > > Bert-Jan > > -- > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com