diff options
author | Adam Bard <github@adambard.com> | 2015-10-31 18:18:37 +0800 |
---|---|---|
committer | Adam Bard <github@adambard.com> | 2015-10-31 18:18:37 +0800 |
commit | aa32e08a052e24477261126d03407e143d39000d (patch) | |
tree | 72bb0859e825b9b6bc00b2e290881e33da08a8d5 /java.html.markdown | |
parent | 1d2b885d93f9733a9af6183872365f3857fc3538 (diff) | |
parent | f7af2da9dbb504377c2ff7c2f29a55b9f363a4c1 (diff) |
Merge pull request #1929 from hopesenddreams/patch-2
Added BigDecimal float constructor caveat
Diffstat (limited to 'java.html.markdown')
-rw-r--r-- | java.html.markdown | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/java.html.markdown b/java.html.markdown index 2836f601..9423c4d9 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -144,7 +144,12 @@ public class LearnJava { // or by initializing the unscaled value (BigInteger) and scale (int). BigDecimal fooBigDecimal = new BigDecimal(fooBigInteger, fooInt); - + + // Be wary of the constructor that takes a float or double as + // the inaccuracy of the float/double will be copied in BigDecimal. + // Prefer the String constructor when you need an exact value. + + BigDecimal tenCents = new BigDecimal("0.1"); // Strings |