I GET SOA STRING USE Double.parseDouble fd.setFdrRate(Double.parseDouble(coreFD.getInterestRate())); message SOA return 3.7 but screen show 3.7000000000000005 save Database return 3.7 help me to check
Asked
Active
Viewed 62 times
0
-
Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Abhijit Sarkar Aug 18 '20 at 02:16
-
What is the screen that shows 3.7000000000000005? Where did that number come from – Joni Aug 18 '20 at 02:51
-
screen show fields return SOA – Đỗ Quang Đức Aug 18 '20 at 04:06
1 Answers
-1
double
cannot represent the number 3.7
with full precision. You may consider using BigDecimal instead:
new BigDecimal(coreFD.getInterestRate()).toString() // 3.7
P.S. Always use BigDecimal
(or similar-purpose class) for storing finance-related numbers.

Andrew Vershinin
- 1,958
- 11
- 16
-
I cannot redo the error on my computer. Are you sure it will fix it? – Đỗ Quang Đức Aug 18 '20 at 02:02
-
This is a dup, please try to refer to the original answer for everyone’s benefit. https://stackoverflow.com/q/588004/839733 – Abhijit Sarkar Aug 18 '20 at 02:16
-