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

Sales tax calculation

Status
Not open for further replies.

CK8

Technical User
Nov 5, 2001
15
US
When I calculate the sales tax on a form I want it to round off to 2 decimals in its calculation. Right now I end up with a long decimal for calculation purposes and this will leave the calculation over or under by one cent on occassion.
 
under the fields properties set the format to fixed and the decimal place to 2
 
formatting will retain the long decimal, but make it appear to be 2 places. if you really want it to be rounded to two decimal places, use:

(int(([value]+.005)*100))/100

g
 
Thanks for the info ... however

Where do I put the (int(([vaule]+.0050*100))/100


Cliff
 
Int would only work if the value is less than about $320.....

The general formula for rounding is....

=CLng(([Value]*10^([NumberOfDP])+0.5)/(10^[NumberOfDP])

This should be put int the control source of your text box.

Craig
 
CK8--yes put it in the control source of your text box

=(int(([value]+.005)*100))/100

craig your formula doesnt' seem to work for me. It's missing a right paren ) some place:

when I put it at the end all i am getting is an integer, not a number with 2 decimal places.

when I put it after the first [NumberOfDP] it is .01 too high for original values which have the hundreths digit <5 (i.e. 16.5221 = 16.53 instead of 16.52)

I think you need to add .005, not .5 really in your forumula it would be:

Code:
.5/(10*[NumberOfDP])

so i think your forumula, which is essentially the same as mine except that I sort of hard-code in the 2 decimal places, should be:

=CLng(([Value]*10^([NumberOfDP]))+0.5/(10*[NumberOfDP]))/(10^[NumberOfDP])

g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top