Decimals are still showing after calculation

TxStrob

Registered User.
Local time
Today, 09:17
Joined
Sep 23, 2019
Messages
44
I have set the field in the table to single, and 0 decimals. In the form I have applied general number and 0 decimals. What else may I be missing to not show decimals?

I do not want the values to be rounded up for example 100/1.5+1 = 67.66666666666667, i just want the text box to show 67 in the form.
 
Try using Fixed and 0 decimals or Round(calculated value, 0)
If you don't want rounding up use Int(calculated value) or Fix(calculated value)
 
thank you so much :)
 
Try using Fixed and 0 decimals or Round(calculated value, 0)
If you don't want rounding up use Int(calculated value) or Fix(calculated value)

It is vital to be aware that some non-integer floating point values cannot be stored accurately in binary and small discrepancies can occur in calculations. Access will sometime hide the errors by rounding.

However, applying Int() or Fix() to the result can cause substantial errors where a calculation should return an integer but the result is slightly imprecise due to this issue.

The following expression is an example using a fractional number which gives unexpected results. (Copy it into the Immediate Window and press enter.)

Code:
? Int(90 * 0.7)

Still wrong even forcing the use of double precision floating point datatypes:
Code:
? Int(CDbl(90) * CDbl(0.7))

Where calculations really matter with fractional values, use the Decimal datatype which stores numbers as integers with a scaling factor. (Many developers also use Currency datatype, which is a special Decimal type having a fixed scale factor of four, ensuring it can be relied on for currency calculations.)

These expressions return the correct answer.

Code:
? Int(90 * CDec(0.7))
? Int(90 * CCur(0.7))
 
Last edited:
Good point
CInt(90*0.7) also gives 63 rather than 62
As does int(ccur(90*0.7)) or fix(ccur(90*0.7)) or abs(ccur(90*0.7))
 
Last edited:
CInt(90*0.7) also gives 63 rather than 62
As does int(ccur(90*0.7)) or fix(ccur(90*0.7)) or abs(ccur(90*0.7))

Yes because the conversion rounds the result at the fourth decimal place for currency where it is correct and of course at the Integer.

The problem occurs when Int() is applied without first rounding the result of the floating point calculation.
 
And ALL of that is necessary because you are dealing with a BINARY fraction but then trying to multiply by a number that is a DECIMAL fraction when presented, but has to be converted to a binary fraction to use it in hardware-based math. If it is a decimal fraction, one of its factors is 5 (i.e. 0.1 = 1/10 = 1/2 * 1/5). The problem child is 1/5 which, being an odd number, cannot be exactly expressed in binary, which can only exactly represent fractions based SOLELY on the power of 2.
 

Users who are viewing this thread

Back
Top Bottom