Partager via


Numeric Data Type

To indicate magnitude, use the Numeric data type. Numeric values contain digits from 0 to 9 and, optionally, a sign and a decimal point. Visual FoxPro supports hexadecimal values for numeric data. For example, the decimal value 255 can be represented as 0xFF.

Tip

For precise financial calculations, use the Currency data type instead of Numeric. You can convert values from Numeric to Currency and the reverse using the NTOM( ) and MTON( ) functions. For more information, see Currency Data Type, NTOM( ) Function, and MTON( ) Function.

In fields with Numeric data type, the length of the decimal portion is determined at design time when you create the field. The length of the decimal portion is part of the total length. For example, if you specify a length of 6 for a numeric field and a decimal setting of 4, the field can store values up to 9.9999.

For specifications about the Numeric data type, see Visual FoxPro Data and Field Types.

Numeric Precision

When storing floating-point numbers in Numeric fields, numeric precision is limited to approximately 15 digits in Visual FoxPro. Therefore, precision more than 15 digits might be lost when converting from decimal to binary numbers, storing numbers with infinitely repeating decimal values in binary, performing multiple repeated operations, and storing numeric values in Character fields and in memory variables in binary format.

This limitation is based on the way Pentium-based processors calculate and store floating-point numbers and follows the Institute of Electrical and Electronics Engineers (IEEE) floating-point specification for manipulating floating-point numbers in binary format. This standard makes it possible for floating-point numbers to be stored in reasonable amount of space and for performing calculations more quickly.

For example, the fraction 1/10 can be represented as a decimal value of 0.1. However, when storing 1/10 in binary, the decimal value is not the same as the fraction. Instead, the fraction is a repeating binary decimal of 0001100110011100110011 and so on. This type of number cannot be represented in memory that is finite or limited; therefore, the decimal value is rounded when stored in binary.

For values requiring higher precision, see Double Field Type.

For more details about floating-point numbers are stored and how Pentium-based processors handle their calculation, see the Microsoft Knowledge Base Article Q78113, "XL: Floating-Point Arithmetic May Give Inaccurate Results" in the MSDN Library at https://msdn.microsoft.com/library/.

The following example illustrates the limit on numeric precision for floating-point numbers for Numeric data types:

x=1234567890.0987654321 
? x

The result is 1234567890.0987650000.

See Also

Tasks

How to: Choose Data Types

Concepts

Creating Numeric Expressions

Reference

Numeric Operators

Other Resources

Data and Field Types