[MarkLogic Dev General] fn:format-number with fixed trailing 0's padded
David Sewell
dsewell at virginia.edu
Fri Sep 2 13:57:04 PDT 2011
This is a MarkLogic bug, based on the spec for fn:format-number. See
http://www.w3.org/TR/xpath-functions-30/#formatting-the-number
point 8: "If the number of digits to the right of the decimal-separator-sign is
less than minimum-fractional-part-size, trailing zero-digit-sign characters are
added to pad out to that size." I.e., if the formatting picture shows two 0's to
the right of the decimal, the output must have two digits, even if the last one
is 0.
David
On Fri, 2 Sep 2011, semerau at hotmail.com wrote:
>
> It looks like if the last digit in the pad is a zero it is dropped:
>
> Note:I added another zero in the number
>
> Examples:
> fn:format-number(43.702402, "#,##0.000")
> => 43.702
>
> fn:format-number(43.702402, "#,##0.0000")
> => 43.7024
>
> fn:format-number(43.702402, "#,##0.00000")
> => 43.7024
>
> fn:format-number(43.702402, "#,##0.000000")
> => 43.702402
>
>
>
>> From: dlee at epocrates.com
>> To: general at developer.marklogic.com
>> Date: Fri, 2 Sep 2011 19:49:01 +0000
>> Subject: Re: [MarkLogic Dev General] fn:format-number with fixed trailing 0's padded
>>
>> Will do.
>> Unfortunately the spec documents are so complicated I cant tell for *sure* whats supposed to happen.\
>> Or maybe its my caveman brain :)
>>
>>
>> ----------------------------------------
>> David A. Lee
>> Senior Principal Software Engineer
>> Epocrates, Inc.
>> dlee at epocrates.com
>> 812-482-5224
>>
>>
>> -----Original Message-----
>> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of John Snelson
>> Sent: Friday, September 02, 2011 3:46 PM
>> To: General MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] fn:format-number with fixed trailing 0's padded
>>
>> Yes, me too. I think there's a bug in there somewhere. Can you get in contact with support about this?
>>
>> John
>>
>> On 2 Sep 2011, at 20:04, Lee, David wrote:
>>
>>> Try this in ML ... I dont get it but I'm sure its burried in the rules somewhere
>>>
>>>
>>> fn:format-number(43.70242, "#,##0.00")
>>>
>>> I get
>>>
>>> 43.7
>>>
>>>
>>>
>>>
>>> ----------------------------------------
>>> David A. Lee
>>> Senior Principal Software Engineer
>>> Epocrates, Inc.
>>> dlee at epocrates.com
>>> 812-482-5224
>>>
>>>
>>> -----Original Message-----
>>> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of John Snelson
>>> Sent: Friday, September 02, 2011 2:51 PM
>>> To: general at developer.marklogic.com
>>> Subject: Re: [MarkLogic Dev General] fn:format-number with fixed trailing 0's padded
>>>
>>> My understanding of the spec is that the picture string "#,##0.00"
>>> should give you a minimum of two digits after the decimal point. It
>>> certainly works that way for me in MarkLogic.
>>>
>>> fn:format-number(5.6, "#,##0.00")
>>>
>>> gives
>>>
>>> "5.60"
>>>
>>> Are you using a recent version of 4.2?
>>>
>>> John
>>>
>>> On 02/09/11 18:31, Lee, David wrote:
>>>> I'm trying to figure out fn:format-number
>>>>
>>>> The specs are about the most confusing thing I've ever read
>>>>
>>>> http://www.w3.org/TR/xpath-functions-30/#syntax-of-picture-string
>>>>
>>>> Could someone give me an example that would format a decimal with a
>>>> fixed number of 0 padded fraction digits ?
>>>>
>>>> For example
>>>>
>>>> format with 2 0 digits padded
>>>>
>>>> 1 as 1.00
>>>>
>>>> 1.4 as 1.40
>>>>
>>>> 1.414 as 1.41
>>>>
>>>> 0 as 0.00
>>>>
>>>> 100.1 as 100.10
>>>>
>>>> I've tried both
>>>>
>>>> "#,##0.##"
>>>>
>>>> and
>>>>
>>>> "#,##0.00"
>>>>
>>>> and both seem to omit the trailing 0
>>>>
>>>> Any suggestions ?
>>>>
>>>> ----------------------------------------
>>>>
>>>> David A. Lee
>>>>
>>>> Senior Principal Software Engineer
>>>>
>>>> Epocrates, Inc.
>>>>
>>>> dlee at epocrates.com <mailto:dlee at epocrates.com>
>>>>
>>>> 812-482-5224
>>>>
>>>
>>>
>>> --
>>> John Snelson, Senior Engineer http://twitter.com/jpcs
>>> MarkLogic Corporation http://www.marklogic.com
>>> _______________________________________________
>>> General mailing list
>>> General at developer.marklogic.com
>>> http://developer.marklogic.com/mailman/listinfo/general
>>> _______________________________________________
>>> General mailing list
>>> General at developer.marklogic.com
>>> http://developer.marklogic.com/mailman/listinfo/general
>>
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
>
--
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville, VA 22904-4314 USA
Email: dsewell at virginia.edu Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/
More information about the General
mailing list