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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Roundig question

Status
Not open for further replies.

fiep

Technical User
Sep 2, 2003
66
NL
I have trouble with calculating some percentages.
This is the code:
all variables are declared as single

sngPerTotal = sngTotalOrdered \ (sngTotal \ 100)
sngTransCost = (sngTranport\100) * sngPerTotal

The problem is that it sngTransport = 150 I still get a value of 1.
So it looks like Access uses an integer for the calculation instead of a single.

What am I doing wrong here? How do I make sure that I get 1.5 as the result?

W.
 
Hi,

Your variable should be set to a double I think, not a single.

Andrew
 
Hi,

use CSng conversion function
Code:
sngPerTotal = CSng(sngTotalOrdered \ (sngTotal \ 100))
sngTransCost = CSng((sngTranport\100) * sngPerTotal)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi fiep,

There's nothing that shouldn't work in what you've posted. What are the values of all the other variables?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Have you tried this ?
sngTransCost = (sngTranport * sngPerTotal) \ 100

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
OK. Do not know what is wrong yet. But I found a workaround and a solution for me.

For instance Iif the variables have the following values:
sngTranport = 150
sngPerTotal = 95
sngTransCost = (sngTranport\100) * sngPerTotal

the calculation: sngTranport\100 would return 1 as result instead of 1,5.

So I changed the code into this:
sngTranport * 0.01
This will give the result of 1,5. I did not change the names or the types of the variables.

Can anyone explain the difference between the two options? Of course 100 is an integer but it is not possible to change that to 100.00 to make it a real (single or double). because the (VBA) editor changes that to 100 as soon as you type it.

Thanks for the suggestions and I hope somebody can explain this behavior.

W.

 
Hi fiep,

I've just spotted what is wrong.

You are using the Integer Divide Operator ([red]\[/red]). It should work as you want if you use the forward slash ([red]/[/red]) for 'normal' division.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Perfect that is it.

Thanks,

W.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top