Skip to content

Commit 285c26e

Browse files
committed
LDEV-6043 fix DecimalFormat bug
1 parent 09b865e commit 285c26e

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

core/src/main/java/lucee/runtime/op/Caster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ public static String toDecimal(double value, boolean separator) {
10081008

10091009
private static String toDecimal(double value, char decDel, char thsDel) {
10101010
// TODO Caster toDecimal bessere impl.
1011-
String str = Caster.toBigDecimal((StrictMath.round(value * 100) / 100D)).toString();
1011+
String str = Caster.toBigDecimal((StrictMath.round(value * 100) / 100D)).toPlainString();
10121012
// str=toDouble(value).toString();
10131013
String[] arr = str.split("\\.");
10141014

loader/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="core" basedir="." name="Lucee"
33
xmlns:resolver="antlib:org.apache.maven.resolver.ant">
44

5-
<property name="version" value="6.2.5.15-SNAPSHOT"/>
5+
<property name="version" value="6.2.5.16-SNAPSHOT"/>
66

77
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
88
<classpath>

loader/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.lucee</groupId>
55
<artifactId>lucee</artifactId>
6-
<version>6.2.5.15-SNAPSHOT</version>
6+
<version>6.2.5.16-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>Lucee Loader Build</name>

test/tickets/LDEV6043.cfc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
component extends="org.lucee.cfml.test.LuceeTestCase" {
2+
3+
function beforeAll() {
4+
variables.preciseMath = getApplicationSettings().preciseMath;
5+
}
6+
7+
function afterAll() {
8+
application action="update" preciseMath=variables.preciseMath;
9+
}
10+
11+
function run( testResults, testBox ) {
12+
describe( title="test case for LDEV-6043", body=function() {
13+
14+
afterEach( function() {
15+
application action="update" preciseMath=variables.preciseMath;
16+
});
17+
18+
it( "DecimalFormat with large numbers should not use scientific notation", function() {
19+
expect( DecimalFormat( 10000000 ) ).toBe( "10,000,000.00" );
20+
expect( DecimalFormat( 20000000 ) ).toBe( "20,000,000.00" );
21+
expect( DecimalFormat( 100000000 ) ).toBe( "100,000,000.00" );
22+
expect( DecimalFormat( 1000000000 ) ).toBe( "1,000,000,000.00" );
23+
});
24+
25+
it( "DecimalFormat with negative large numbers", function() {
26+
expect( DecimalFormat( -10000000 ) ).toBe( "-10,000,000.00" );
27+
expect( DecimalFormat( -20000000 ) ).toBe( "-20,000,000.00" );
28+
});
29+
30+
it( "DecimalFormat boundary values around scientific notation threshold", function() {
31+
expect( DecimalFormat( 9999999 ) ).toBe( "9,999,999.00" );
32+
expect( DecimalFormat( 19999999 ) ).toBe( "19,999,999.00" );
33+
expect( DecimalFormat( 20000001 ) ).toBe( "20,000,001.00" );
34+
});
35+
36+
it( "DecimalFormat with large numbers and preciseMath=true", function() {
37+
application action="update" preciseMath=true;
38+
expect( DecimalFormat( 10000000 ) ).toBe( "10,000,000.00" );
39+
expect( DecimalFormat( 20000000 ) ).toBe( "20,000,000.00" );
40+
expect( DecimalFormat( 100000000 ) ).toBe( "100,000,000.00" );
41+
});
42+
43+
it( "DecimalFormat with large numbers and preciseMath=false", function() {
44+
application action="update" preciseMath=false;
45+
expect( DecimalFormat( 10000000 ) ).toBe( "10,000,000.00" );
46+
expect( DecimalFormat( 20000000 ) ).toBe( "20,000,000.00" );
47+
expect( DecimalFormat( 100000000 ) ).toBe( "100,000,000.00" );
48+
});
49+
50+
});
51+
}
52+
53+
}

0 commit comments

Comments
 (0)