Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation Mistake!!! 1

Status
Not open for further replies.

Fekri

Programmer
Jan 3, 2004
284
IR
Hi,

I have seen a strange calculation in access!!!

I have a Invoice form and there is subform which have 3 bound textbox.
in subform record souce, I have a calculation like this:

Subtotal: [text1]*[text2]
The problem is:
every thing works ok, just some times in depend of value of [text1] or [text2], calculation result will be +1 or -1?????
FOr example:

923.1*31500 = 29077649 !!!!!
362.3*30700 = 11122610

some numbers are ok some not!!!!!!!!!

Thanks for any idea or help
Ali

Thanks & Good Luck
Ali Fekri
 
I think I have to explain more:

[Text1] is Number and [text2] is curency.

I used CCur to calculate it, and some calculation will be ok others no!!
I didn't used CCur others became ok and other backed to misscaculate!!!

Big Strange for me
Please help me!!!!
Ali Fekri

Thanks & Good Luck
Ali Fekri
 
Check your formating on both numbers (in there tables). Sometimes in Access, the numbers carry their decimals out further then they appear, and just show you the rounded number.

Thanks for the help.
Greg
 
TEXT boxes contain TEXT. You can FORMAT it any way you like, but it is still not a numeric datatype.
Use CDec(), CCur(), CInt(), etc. to convert before calculating.

When everything is coming your way, you're in the wrong lane.
 
Tnanks for your replies,

But many days past and I'm still crasy with this calculation!!!
I used Cdec(), ccur(), Cint(), rtc... before and after calculation, but still the problem is exist!!!!

It's very strange for me, what the other people who are using access are doing???
the both number which to be calculatied is entering by the user without any decimal!! but in the result will appear many decimal!!!
You can try too with these numnbers whcih I gave you and you will se the mistake!!!!!!!!!

Thanks for any idea...
Ali Fekri

Thanks & Good Luck
Ali Fekri
 
Have you set up a format for each text box, particularly the one that is a number (rather than currency)? It should be something like a fixed number with a specific number of decimal places. Then you should be able to use the [Text1]*[Text2] calculation with no problem (assuming that neither one contains a null value).

Bob
 
Thanks for your repli,

But the data in both textbox is written by the user and they are fixed number with max 2 decimal.

but why in result decimal will apear?

For example: 1020.1 * 32300 should be 32949230

But the result will appear: 32,949,229.2114

Why???


Thanks & Good Luck
Ali Fekri
 
Except for currency, any number with a decimal value (i.e., not an integer) is stored in a binary format. Binary cannot accurately record exact decimal values. When you multiply, the result can be a little different because of the fact that the original values are very slightly off of what you think they are. For example, 1020.1 might actually be stored as the value 1020.999648321 because of the problems in storing as a base 2 (binary) number. Currency is stored in a format which has been called "binary coded decimal", which basically translates the number on each side of the decminal point to an integer stored in binary and can therefore return the exact decimal value.

You might try rounding the result to two decimal places before you write it. In addition, set the target control as a 2 decimal place number format once you have the rounding working well.

This problem usually shows up when you are either multiplying larger numbers and/or you are adding a lot of numbers with decimal places. It's an old problem.

Bob
 
Genomon, where in the world did you get the idea that all data in a textbox is text? The datatype is whatever it's defined as in the table, and textboxes can hold numbers and currency and dates/times and memos and hyperlinks as well as text!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for your attention but,

I hate to show decimal place always in my textboxes in form. and I need decimal when the number has decimal!!
So, Always I make zero the decimal place in my textboxed .
and all my currency have no any decimal, because our local currency hasn't any decimal!!
So, in the result of this multply, I need the rounded number as a calculator will show. It means if I used my calculator instead of computer, the result of this multiply is :32949230!!!!
how you think I can use round function to get this result???


Thanks
Ali

Thanks & Good Luck
Ali Fekri
 
How are ya Fekri . . .


Have you tried:
Code:
[blue]Subtotal: CCur([text1])*CCur([text2])[/blue]
If [Text2] is actually currency datatype, then you can drop its [blue]CCur[/blue] conversion.

The problem your having involves [blue]coercing[/blue]. With mixed data types access has to determine what data type to return. I have the rules for coercing in a query in my library, just havn't found it yet. I'll post again when I do.


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
AceMan: Amen.
[angel]

Money can't buy happiness -- but somehow it's more comfortable to cry in a Corvette than in a Yugo.
 
genomon . . .

Forgive me . . . but I'm not sure if your Amen means it worked or not?

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Thanks Theaceman,

I used last time CCur([text1]*[text2]) & [text1]*ccur([text2])

because [text1] was number not currency!!

but the result was as the same before.
Now, with your recomendation, to use CCur for both textbox,
it works great.

Thanks a lot
and many thanks to all for their help.
Ali

Thanks & Good Luck
Ali Fekri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top