- From: Philip Fennell <Philip.Fennell@marklogic.com>
- Date: Wed, 24 Jan 2018 10:39:46 +0000
- To: Erik Bruchez <ebruchez@orbeon.com>, Steven Pemberton <steven.pemberton@cwi.nl>
- CC: XForms <public-xformsusers@w3.org>
- Message-ID: <FABA160E-70B7-4D4A-9478-DA1C80B005B1@marklogic.com>
Erik wrote: > I would vote for `format-number()` so we don't have to reinvent the wheel. I agree. From: <ebruchez@gmail.com> on behalf of Erik Bruchez <ebruchez@orbeon.com> Date: Tuesday, 23 January 2018 at 17:15 To: Steven Pemberton <steven.pemberton@cwi.nl> Cc: XForms <public-xformsusers@w3.org> Subject: Re: Support for decimal type Resent-From: <public-xformsusers@w3.org> Resent-Date: Tuesday, 23 January 2018 at 17:14 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. 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. -Erik
Received on Wednesday, 24 January 2018 10:40:11 UTC