Full Version: calculations not really 2 decimal places
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
fairlo
Hi

i hope this is in the right area.

i have a piece of code which performs a calculation. The fields it takes its figures from are set to decimal with 2 decimal places. However when the calculation is performed it returns an answer allways with .00 even if the answer should have numbers after the decimal point. Whilst performing the calculations i use dim tempname as integer to hold the vaule. any ideas i really need the calculations worked out to 2 decimal places, not rounded up and .00 added

thanks all
bome
"dim tempname as integer" makes the variable tempname store integer values (whole numbers) only. Use a different datatype instead that can store decimal numbers (single, double, currency).
__________
Bo Melin
fairlo
thanks i tried changing it to as double but i still get .00 for every calculation. It just rounds up or down the answer an adds .00 to it.

any other sugestions?
bome
If the text box for the result in the form is bound to a table column, make sure the data type in the table column can store decimal numbers.
___________
Bo Melin

Edited by: bome on Wed Oct 24 17:10:43 EDT 2007.
MartinWHughes
If I need a true 2DP answer to a calculation I always use:
Int([calculation])*100+.5)/100
i.e. perform calculation - multiply result by 100 and add 0.5 (performs normal rounding) then take the integer value of this and divide by 100.
This always gives a true 2DP result and means that doing things like adding totals on an Invoice always adds "correctly"

Regards
Martin

Edited by: MartinWHughes on Thu Oct 25 5:18:27 EDT 2007.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.