- From: Erik Bruchez <ebruchez@orbeon.com>
- Date: Tue, 23 Jan 2018 09:14:04 -0800
- To: Steven Pemberton <steven.pemberton@cwi.nl>
- Cc: XForms <public-xformsusers@w3.org>
- Message-ID: <CAAc0PEWt=m7_CXNcRH5E-pyFAmv-KabzpAiQDpEFig_6dneO8Q@mail.gmail.com>
> > 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 Tuesday, 23 January 2018 17:14:52 UTC