You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/10/04 12:26:02 UTC
[camel] 05/07: (chores) camel-bindy: avoid subtle bugs caused by rounding errors
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 734b5c5a7cec1f23dad80c2758f28c8874dda36f
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Oct 4 11:50:27 2022 +0200
(chores) camel-bindy: avoid subtle bugs caused by rounding errors
Floating point numbers cannot be properly represented as an IEEE 754 floating-point value.
Ref.: https://wiki.sei.cmu.edu/confluence/display/java/NUM10-J.+Do+not+construct+BigDecimal+objects+from+floating-point+literals
---
.../dataformat/bindy/format/factories/BigDecimalFormatFactory.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
index 197b1343b07..db0d2da62bc 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactory.java
@@ -54,14 +54,14 @@ public class BigDecimalFormatFactory extends AbstractFormatFactory {
public String format(BigDecimal object) throws Exception {
return !super.hasImpliedDecimalPosition()
? super.getFormat().format(object)
- : super.getFormat().format(object.multiply(new BigDecimal(super.getMultiplier())));
+ : super.getFormat().format(object.multiply(BigDecimal.valueOf(super.getMultiplier())));
}
@Override
public BigDecimal parse(String string) throws Exception {
BigDecimal result = new BigDecimal(string.trim());
if (super.hasImpliedDecimalPosition()) {
- result = result.divide(new BigDecimal(super.getMultiplier()), super.getPrecision(), RoundingMode.HALF_EVEN);
+ result = result.divide(BigDecimal.valueOf(super.getMultiplier()), super.getPrecision(), RoundingMode.HALF_EVEN);
} else {
if (super.getPrecision() != -1) {
result = result.setScale(super.getPrecision());