Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applications using Decimal versus double . .

I wanted to see if folks were using decimal for financial applications instead of double. I have seen lots of folks using double all over the place with unintended consequences . .

Do you see others making this mistake . . .

like image 204
leora Avatar asked Oct 24 '08 03:10

leora


People also ask

Should I use decimal or double?

If numbers must add up correctly or balance, use decimal. This includes any financial storage or calculations, scores, or other numbers that people might do by hand. If the exact value of numbers is not important, use double for speed.

What is difference between decimal and double?

The fundamental difference is that the double is a base 2 fraction, whereas a decimal is a base 10 fraction. double stores the number 0.5 as 0.1, 1 as 1.0, 1.25 as 1.01, 1.875 as 1.111, etc. decimal stores 0.1 as 0.1, 0.2 as 0.2, etc.

What is the benefit of the decimal type over the float and double types?

Decimal can 100% accurately represent any number within the precision of the decimal format, whereas Float and Double, cannot accurately represent all numbers, even numbers that are within their respective formats precision.

Which is more precise double or decimal?

Decimal is more precise than double because it has more bits of precision.


1 Answers

We did unfortunately and we regret it. We had to change all doubles to decimals. Decimals are good for financial applications. You can look at this article A Money type for the CLR:

A convenient, high-performance money structure for the CLR which handles arithmetic operations, currency types, formatting, and careful distribution and rounding without loss.

like image 107
jfs Avatar answered Sep 20 '22 23:09

jfs