From 3c491cf6714584371603089649430f3227101a75 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Mon, 14 Apr 2025 17:33:40 -0300 Subject: [PATCH] Format BigDecimal values must round HALF_UP Issue 203511 --- common/src/main/java/com/genexus/LocalUtil.java | 2 ++ java/src/test/java/com/genexus/TestCommonUtil.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/common/src/main/java/com/genexus/LocalUtil.java b/common/src/main/java/com/genexus/LocalUtil.java index bb2986c81..1f5dd0634 100644 --- a/common/src/main/java/com/genexus/LocalUtil.java +++ b/common/src/main/java/com/genexus/LocalUtil.java @@ -1,5 +1,6 @@ package com.genexus; +import java.math.RoundingMode; import java.util.*; import java.text.*; @@ -1713,6 +1714,7 @@ private String formatBigDecimal(java.math.BigDecimal value, String picture, Numb { DecimalFormat df = (DecimalFormat) numberFormat; df.applyPattern(pictureToNumberFormat(withoutSuffixPicture)); + df.setRoundingMode(RoundingMode.HALF_UP); if ( CommonUtil.in(picture, '.') || CommonUtil.in(picture, ',')) { formatted = alignAndPad(df.format(value), '0', withoutSuffixPicture, floating, numberFormat, originalPicture); diff --git a/java/src/test/java/com/genexus/TestCommonUtil.java b/java/src/test/java/com/genexus/TestCommonUtil.java index 8857ee67f..970cfd1fc 100644 --- a/java/src/test/java/com/genexus/TestCommonUtil.java +++ b/java/src/test/java/com/genexus/TestCommonUtil.java @@ -204,6 +204,13 @@ public void testFormat() { result = ui.getLocalUtil().format(bigDecimalValue, picture); Assert.assertEquals(expectedResult, result); + bigDecimalValue = new BigDecimal(2.5); + picture = "Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9"; + expectedResult = " 3"; + + result = ui.getLocalUtil().format(bigDecimalValue, picture); + Assert.assertEquals(expectedResult, result); + bigDecimalValue = new BigDecimal(-12.5); picture = "$Z9.9"; expectedResult = "-$12.5";