You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The round(num, decimalPlaces) function doesn't work on locales that use comma as the decimal mark (Polish Locale for example:)).
Steps to reproduce the problem
I reproduced this problem by running the test suite on my machine which has PL locale.
The suite crashes with the following information:
java.lang.NumberFormatException: For input string: "14,3"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at java.lang.Double.valueOf(Double.java:502)
at org.javarosa.xpath.expr.XPathFuncExpr.round(XPathFuncExpr.java:1055)
at org.javarosa.xpath.expr.XPathFuncExpr.eval(XPathFuncExpr.java:200)
at org.javarosa.xpath.test.XPathEvalTest.testEval(XPathEvalTest.java:86)
at org.javarosa.xpath.test.XPathEvalTest.testEval(XPathEvalTest.java:65)
at org.javarosa.xpath.test.XPathEvalTest.doTests(XPathEvalTest.java:322)
This comes from test for "round('14.29123456789', 1)" expression but I checked and the suite will fall for any round expression that have more than 0 as the power parameter.
Expected behavior
The test just passes.
Other information
The following code causes this behaviour:
final NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(numDecimals);
nf.setGroupingUsed(false);
return Double.valueOf(nf.format(number));
It uses NumberFormat's capabilities to round a decimal number. It works great but this class follows the current locale settings and produces a readable string that matches the locale's rules. The result is later passed to Double.valueOf which doesn't handle comma as the decimal separator.
For example, in Poland nf.format(number) for number=14.29123456789 and numDecimals=1 will return 14,3 instead of 14.3.
The text was updated successfully, but these errors were encountered:
Software versions
JavaRosa since 7d0e596 (PR #33 , Issue #5).
Problem description
The
round(num, decimalPlaces)
function doesn't work on locales that use comma as the decimal mark (Polish Locale for example:)).Steps to reproduce the problem
I reproduced this problem by running the test suite on my machine which has PL locale.
The suite crashes with the following information:
This comes from test for "round('14.29123456789', 1)" expression but I checked and the suite will fall for any round expression that have more than 0 as the power parameter.
Expected behavior
The test just passes.
Other information
The following code causes this behaviour:
It uses NumberFormat's capabilities to round a decimal number. It works great but this class follows the current locale settings and produces a readable string that matches the locale's rules. The result is later passed to
Double.valueOf
which doesn't handle comma as the decimal separator.For example, in Poland
nf.format(number)
fornumber=14.29123456789
andnumDecimals=1
will return14,3
instead of14.3
.The text was updated successfully, but these errors were encountered: