Decimals rounding without wanting them too.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table and I'm supposed to be entering quantities of fabric being
used and these quantities are decimals. But it just keeps rounding. I don't
know why and I have to fix it because it becomes part of a pricing equation.
Please Help.
Thanks in Advance.
Travis
 
I have a table and I'm supposed to be entering quantities of fabric being
used and these quantities are decimals. But it just keeps rounding. I don't
know why and I have to fix it because it becomes part of a pricing equation.
Please Help.
Thanks in Advance.
Travis

Usually it's because the field's datatype has incorrectly been set to
Number, Integer Field Size.
An Integer, by definition is a whole number and cannot have a decimal
part.
Change the Field size property to single or double.
 
Welcome to computers, and decimal math!!!

Take the following code in ms-access

Public Sub TestAdd()


Dim MyNumber As Single
Dim i As Integer


For i = 1 To 10
MyNumber = MyNumber + 1.01
Debug.Print MyNumber
Next i
End Sub


Here is the actual output of the above:


1.01
2.02
3.03
4.04
5.05
6.06
7.070001
8.080001
9.090001
10.1


You can see that after just 7 additions..already rounding is occurring

and if we add the following line of code to the end of the above:

if MyNumber = 10.1 = True then
msgbox "the number is 10.1"
else
msgbox "the number is somthing else"
endif


The above will actual produce:

the number is something else

What the above means that decimal numbers represented in a computer are only
a approximation. The solution is to user integer numbers, or in the case of
financial calculations, use currency data type. (the currency data type is a
actually a scaled integer,a nd it fakes the decimal repression by
representation integer..and moving the decimal point).

Try changing your data types to currency, and that should cure your rounding
problems...
 
Albert said:
Try changing your data types to currency, and that should cure your rounding
problems...

Or indeed to the DECIMAL data type e.g. the OP hasn't specified but the
values involved may have more than four decimal places.

Personally, I'd find it confusing to encounter a schema that modelled
fabric quantities as CURRENCY.

Changing the data type to currency may introduce other more subtle
rounding issues. The CURRENCY type rounds values using a banker's
rounding algorithm, which may not be appropriate to fabric quantities.
The DECIMAL type truncates and therefore may be the way to go if the
aim truly is to eliminate rounding.

Jamie.

--
 
I had a rather large, and perhaps heated debate/exchange on this issue
recently...

I come around a bit on this issue. So, I do now accept that using decimal
type is a reasonable choice here.....
the OP hasn't specified but the
values involved may have more than four decimal places.

Yes, the above is likely the deal breaker issue here. (my guess is .25, .5.
75 etc...but, we really don't know the lengths involved)
Personally, I'd find it confusing to encounter a schema that modelled
fabric quantities as CURRENCY.

That is another fair point. However, support in ms-access is better for
currency data types.

There are pros/cons, and not knowing if any rounding is needed makes this
decision a toss up right now......
 
Albert said:
I come around a bit on this issue. So, I do now accept that using decimal
type is a reasonable choice here.....

support in ms-access is better for
currency

There are pros/cons, and not knowing if any rounding is needed makes this
decision a toss up right now......

In the same spirit, I thank you for presenting a balanced view.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top