# C# double 相加問題
###### tags: `C#`
當一正一負兩個 double 相加,可能出現無限小數點 ex: `1.3 + -1.2 = 0.0999999...`,解決方法強制轉型成 decimal ex:`(decimal)43.65+(decimal)61.11=104.76`,或一開始就存 decimal 吧
適用 decimal 的類型,financial values
適用 float/double 的類型,scientific data
decimal 儲存數度比 float/double 還慢,但需要做運算的數值還是存 decimal 才會準確
### 相關連結
[c#: sum of two double numbers problem](https://stackoverflow.com/questions/5388856/c-sum-of-two-double-numbers-problem)
[Difference between decimal, float and double in .NET?](https://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net)