10

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

1
  • It should be noted that this is probably true for most .net languages. Commented Dec 6, 2010 at 0:29

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

4 Comments

That's what I thought. Why do I often see Double used?
Because some accountants don't lose sleep over a billionth of a penny.
It is not "a billionth of a penny". Binary floating point cannot store 0.02
@LucioM.Tato Or even 0.1. exploringbinary.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.