Skip to content

Commit 15aa854

Browse files
authored
Format BigDecimal values must round HALF_UP (#961)
Issue 203511
1 parent 655ee4c commit 15aa854

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

common/src/main/java/com/genexus/LocalUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.genexus;
22

3+
import java.math.RoundingMode;
34
import java.util.*;
45
import java.text.*;
56

@@ -1713,6 +1714,7 @@ private String formatBigDecimal(java.math.BigDecimal value, String picture, Numb
17131714
{
17141715
DecimalFormat df = (DecimalFormat) numberFormat;
17151716
df.applyPattern(pictureToNumberFormat(withoutSuffixPicture));
1717+
df.setRoundingMode(RoundingMode.HALF_UP);
17161718
if ( CommonUtil.in(picture, '.') || CommonUtil.in(picture, ','))
17171719
{
17181720
formatted = alignAndPad(df.format(value), '0', withoutSuffixPicture, floating, numberFormat, originalPicture);

java/src/test/java/com/genexus/TestCommonUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ public void testFormat() {
204204
result = ui.getLocalUtil().format(bigDecimalValue, picture);
205205
Assert.assertEquals(expectedResult, result);
206206

207+
bigDecimalValue = new BigDecimal(2.5);
208+
picture = "Z,ZZZ,ZZZ,ZZZ,ZZZ,ZZ9";
209+
expectedResult = " 3";
210+
211+
result = ui.getLocalUtil().format(bigDecimalValue, picture);
212+
Assert.assertEquals(expectedResult, result);
213+
207214
bigDecimalValue = new BigDecimal(-12.5);
208215
picture = "$Z9.9";
209216
expectedResult = "-$12.5";

0 commit comments

Comments
 (0)