You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/12/01 13:07:26 UTC
[groovy] branch master updated: Avoid toPlainString() for
converting BigDecimal to BigInteger
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 8479326 Avoid toPlainString() for converting BigDecimal to BigInteger
8479326 is described below
commit 847932633377615c9a5e77ad823f3d7d3b307c0a
Author: MoonFruit <dk...@gmail.com>
AuthorDate: Tue Dec 1 20:06:44 2020 +0800
Avoid toPlainString() for converting BigDecimal to BigInteger
---
.../java/org/codehaus/groovy/runtime/typehandling/NumberMath.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
index 5ee8cfb..299c524 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/NumberMath.java
@@ -187,7 +187,10 @@ public abstract class NumberMath {
if (n instanceof Integer || n instanceof Long || n instanceof Byte || n instanceof Short) {
return BigInteger.valueOf(n.longValue());
}
- return new BigInteger(n instanceof BigDecimal ? ((BigDecimal) n).toPlainString() : n.toString());
+ if (n instanceof BigDecimal) {
+ return ((BigDecimal) n).toBigIntegerExact();
+ }
+ return new BigInteger(n.toString());
}
/**