Re: Support for decimal type

On Tue, 23 Jan 2018 18:14:04 +0100, Erik Bruchez <ebruchez@orbeon.com>  
wrote:

>> I was making a banking app, and realised that there is insufficient  
>> support for using the decimal type.
>>
>> On summing a series of amounts I was getting values like 136.6000000345,
>
> If you deal with xs:decimal throughout, you shouldn't get that kind of  
> results in the first place unless you do divisions, assuming the source  
> data is >good.

Hmm. Sounds like a Test Suite test.

>
>> so I was having to do things like
>>
>>        round(amount*100) div 100
>>
>> Ideally I would have liked the XPath3 function round(d, precision)
>> https://www.w3.org/TR/xpath-functions/#func-round
>
> Funnily enough we have an issue and StackOverflow question about this  
> rounding:
>
>    https://stackoverflow.com/questions/44304839/orbeon-xforms-round-when-formatting-true
>    https://github.com/orbeon/orbeon-forms/issues/3226
>
> It's definitely an omission from XPath 2.
>
>> but that still doesn't solve my problem of formatting 25 as 25.00 or  
>> 25.6 as 25.60
>>
>> XPath3 format-number is a bit heavyweight for my needs
>> https://www.w3.org/TR/xpath-functions/#func-format-number
>
> It comes from XSLT 2, and it's a decent formatting function. We use this  
> for formatting in our number component.
>
>> How about a function decimal(d, 2) yielding a string with 2 places of  
>> accuracy?
>
> The thing is, you quickly have to decide whether you want thousands  
> separators, how you want to represent negative numbers, etc. I would  
> vote for >`format-number()` so we don't have to reinvent the wheel.

How odd that it's in XSLT 2 and not XPath2.

Steven

>
> -Erik

Received on Wednesday, 24 January 2018 10:21:50 UTC