Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET best data type for storing currency values

What is the most appropriate data type for storing currency values in VB.NET?

like image 607
burntsugar Avatar asked Feb 13 '10 00:02

burntsugar


People also ask

Which data type is best for storing currency data?

The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data.

How do databases store money values?

The first important rule is, always store values as fractional units. It can be tempting to store a value such as $10 as 10.00 in your database. However, storing monetary values with a decimal point can cause a lot of issues. Instead, you should always store monetary values in their minor unit form.

How do you add currency to a data type?

Select the cells and then select Insert > Table. Although creating a table isn't required, it'll make inserting data from the data type much easier later. With the cells still selected, go to the Data tab and select the Currencies data type.

What would be a good data type to store prices for an international shopping?

The best type for price column should be DECIMAL. The type DECIMAL stores the value precisely. For Example - DECIMAL(10,2) can be used to store price value. It means the total digit will be 10 and two digits will be after decimal point.


1 Answers

Decimal (alias for System.Decimal structure in the BCL) is designed for storing monetary values. It's a 128 bit decimal floating point type (as opposed to binary floating point) and is useful for storing "real-world" values with high decimal precision. By real-world, I specifically mean measurements that are originally made in decimal. Double is generally suitable for calculations that don't need as much accuracy when they are represented as decimal numbers.

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding. For example, the following code produces a result of 0.9999999999999999999999999999 rather than 1.

like image 91
mmx Avatar answered Oct 31 '22 01:10

mmx