Skip to content

Commit e0e0fc8

Browse files
committed
[bugfix] Fix double negative character issue in negative exponents when using fn:format-number
Closes eXist-db/exist#5943
1 parent ca4910a commit e0e0fc8

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@
791791
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
792792
<include>src/test/xquery/tail-recursion.xml</include>
793793
<include>src/test/xquery/maps/maps.xqm</include>
794+
<include>src/test/xquery/numbers/format-numbers.xql</include>
794795
<include>src/test/xquery/util/util.xml</include>
795796
<include>src/test/xquery/xquery3/parse-xml.xqm</include>
796797
<include>src/test/xquery/xquery3/serialize.xql</include>
@@ -1374,6 +1375,7 @@
13741375
<exclude>src/test/xquery/tail-recursion.xml</exclude>
13751376
<exclude>src/test/xquery/type-promotion.xqm</exclude>
13761377
<exclude>src/test/xquery/maps/maps.xqm</exclude>
1378+
<exclude>src/test/xquery/numbers/format-numbers.xql</exclude>
13771379
<exclude>src/test/xquery/securitymanager/acl.xqm</exclude>
13781380
<exclude>src/test/xquery/util/util.xml</exclude>
13791381
<exclude>src/test/xquery/xqsuite/xqsuite-assertions-dynamic.xqm</exclude>

exist-core/src/main/java/org/exist/xquery/functions/fn/FnFormatNumbers.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,6 @@ private String format(final NumericValue number, final DecimalFormat decimalForm
713713
final int minimumExponentSize = subPicture.getMinimumExponentSize();
714714
if (minimumExponentSize > 0) {
715715
formatted.append(decimalFormat.exponentSeparator);
716-
if (exp < 0) {
717-
formatted.append(decimalFormat.minusSign);
718-
}
719716

720717
final CodePointString expStr = new CodePointString(String.valueOf(exp));
721718

exist-core/src/test/xquery/numbers/format-numbers.xql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
(:
2+
: Elemental
3+
: Copyright (C) 2024, Evolved Binary Ltd
4+
:
5+
6+
: https://www.evolvedbinary.com | https://www.elemental.xyz
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; version 2.1.
11+
:
12+
: This library is distributed in the hope that it will be useful,
13+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
: Lesser General Public License for more details.
16+
:
17+
: You should have received a copy of the GNU Lesser General Public
18+
: License along with this library; if not, write to the Free Software
19+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
:
21+
: NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
: The original license header is included below.
23+
:
24+
: =====================================================================
25+
:
226
: eXist-db Open Source Native XML Database
327
: Copyright (C) 2001 The eXist-db Authors
428
:
@@ -303,4 +327,17 @@ declare
303327
%test:assertEquals("0.0")
304328
function fd:decimal-zeros($picture as xs:string) {
305329
format-number(0, $picture)
330+
};
331+
332+
declare
333+
%test:args("1.234567E10")
334+
%test:assertEquals("1.235e10")
335+
%test:args("1.234567E-10")
336+
%test:assertEquals("1.235e-10")
337+
%test:args("0.00000000123456")
338+
%test:assertEquals("1.235e-9")
339+
%test:args("1.234567e-10")
340+
%test:assertEquals("1.235e-10")
341+
function fd:negative-exponent($value as xs:numeric) {
342+
format-number($value, "0.000e0")
306343
};

0 commit comments

Comments
 (0)