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

Decimal number in a table

Status
Not open for further replies.

pavanlaf

Programmer
Feb 15, 2001
9
0
0
US
Hi.
Does any one know how to define a decimal number in a table (such as GPA)? I tried but it wont work.

Thanks in advance
Pavan.
 
In the design view change the data type to Number and in the properties below change the field size to Double and then select the number of decimal places you want. This is one of many ways.

HTH
JC
 
The decimal data type is not supported by the current versions of Access, with the exception of variant type variables with decimal subtypes. (It will become a native data type in VB.NET late this year, and presumably in the subsequent release of Office.)

If 4 decimal places are enough for your need, try using a Currency datatype. Although it is stored as a binary number, it is scaled, which means you won't have rounding errors converting between decimal and binary.

If you need more decimals than that, you'll have to use a Long and scale it yourself. That means that internally, it's stored as a binary integer, and you do all integer arithmetic, which avoids the base conversion problem. When you input or output the value, you'll have to multiply or divide, respectively, by 10 to the nth power, where n is the number of decimal places you need. You'll also have to do something similar when multilpying or dividing internally, since the results of these operations have a different number of decimal places than their operands. That is, if you multiply together two 3-decimal numbers that have been scaled to integers, the resulting integer must be interpreted as having 6 decimal places, and you have to round and adjust it back to 3. Rick Sprague
 
Rick where did you get this? Access 97 has both single and double floating points data types with a decimal precision of 7 & 15 places respectively and A2K has a data type decimal with 28 places of precision! If this is in error I would appreciate you pointing me to your resources.

Thanks,
JC
 
Mongooses, we must have cross-posted, because your reply wasn't there to make me think twice as I was composing mine.

Since pavanlaf classifies himself as a programmer, I assumed he knew about floating point variables, or at least would have run across them while looking for a Decimal data type in the table design grid. Therefore, I assumed he was looking for the vbDecimal data type, that is, a number stored as radix 10. Singles and Doubles are stored as binary.

For some applications, actual base 10 numbers are important because some decimal fractions can not be expressed exactly as binary fractions (they come out as repeating binary fractions). In such applications, you really need a number stored in decimal radix.

If I'd read more carefully, I would have seen that pavanlaf mentioned GPA, which isn't likely to demand enough precision to have this problem, so your answer was probably what he was looking for.

Besides, after I consulted the data type chart, I see that Currency data types are stored as binary, too. Somehow I'd gotten the idea they were actual decimal types. I must be thinking of another language. Rick Sprague
 
Thanks for responding - you had me thinking (which may or may not be a good thing). Keep up the good work,

JC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top