Good morning,

 

First of all thank you for your great work on basex. I’ve been phasing out Zorba in favour of BaseX for excellent large file support and all around better documentation and support.

 

However, I’m running into some issues in formatting numbers in basex 8.4.4 using fn:format-number (using http://www.w3schools.com/xsl/func_formatnumber.asp)

 

To describe this behavior I wrote a simple xquery:

 

let $result :=

<rows>

  <row input="0.3576" format="0.##" expected="0.36">{fn:format-number(0.3576, "0.##")}</row>

  <row input="-0.3576" format="0.##" expected="-0.36">{fn:format-number(-0.3576, "0.##")}</row>

  <row input="-0.3576" format="0.###" expected="-0.358">{fn:format-number(-0.3576, "0.###")}</row>

  <row input="-0.3576" format="0.####" expected="-0.3576">{fn:format-number(-0.3576, "0.####")}</row>

  <row input="-0.3576" format="0.00" expected="-0.36">{fn:format-number(-0.3576, "0.00")}</row>

  <row input="0.000" format="0.##" expected="0.00">{fn:format-number(0.000, "0.##")}</row>

  <row input="0" format="0.00" expected="0.00">{fn:format-number(0, "0.00")}</row>

  <row input="0.3" format="0.####" expected="0.3">{fn:format-number(0.3, "0.####")}</row>

  <row input="0.3" format="0.0000" expected="0.3000">{fn:format-number(0.3, "0.0000")}</row>

  <row input="17" format="0.##" expected="17">{fn:format-number(17, "0.##")}</row>

  <row input="17" format="0.00" expected="17.00">{fn:format-number(17, "0.00")}</row>

  <row input="17.4555" format="0.##" expected="17.46">{fn:format-number(17.4555, "0.##")}</row>

  <row input="-17.4555" format="0.##" expected="-17.46">{fn:format-number(-17.4555, "0.##")}</row>

</rows>

 

return $result

 

The result of this is as follows:

<rows>

  <row input="0.3576" format="0.##" expected="0.36">.36</row>

  <row input="-0.3576" format="0.##" expected="-0.36">-.36</row>

  <row input="-0.3576" format="0.###" expected="-0.358">-.358</row>

  <row input="-0.3576" format="0.####" expected="-0.3576">-.3576</row>

  <row input="-0.3576" format="0.00" expected="-0.36">-.36</row>

  <row input="0.000" format="0.##" expected="0.00">0</row>

  <row input="0" format="0.00" expected="0.00">0.00</row>

  <row input="0.3" format="0.####" expected="0.3">.3</row>

  <row input="0.3" format="0.0000" expected="0.3000">.3000</row>

  <row input="17" format="0.##" expected="17">17</row>

  <row input="17" format="0.00" expected="17.00">17.00</row>

  <row input="17.4555" format="0.##" expected="17.46">17.46</row>

  <row input="-17.4555" format="0.##" expected="-17.46">-17.46</row>

</rows>

 

 

Unfortunately two things seem to go wrong here:

·         Zero in the picture string is ignored for negative numbers.

·         The zero before decimal is ignored for amounts between zero and one (but does occur for 0.0000 for example).

 

I hope someone can take a look at this and provide a fix.

I tried messing around with string replace functions where I would just replace -. with -0. and prefix the result for a decimal point with a zero, but this really isn’t present and requires a workaround for something that is very common in my code.

 

Using the latest basex (8.4.4) on Windows Server 2012 under Java 8 (64 bit, last update just now: update 91).

 

Thanks in advance and best regards,

Michaël Stoop