format-number rounding

Friday, 13 January 2017 · 2 messages · last reply 14 Jan 2017
GS
George Sofianos13 Jan 2017 14:16 #
Hi there, I was wondering if there is a similar function to format-number, but without rounding, so I don't have to create a custom one that involves string manipulation. For example I have two values:
let $x := <value>15.224134</value>
let $y := <value>15.2249348734</value>
The following command will create different output for the two values (result for $x will be 15.224, result for $y will be 15.225) format-number(xs:decimal($x), "0.000")) Thanks, George
CG
Christian Grün14 Jan 2017 10:02 #
Hi George, I guess you’ll need to write an extra function:
  declare function local:floor(
    $number as xs:decimal,
    $scale  as xs:integer
  ) as xs:decimal {
    let $factor := xs:decimal(math:pow(10, $scale))
    return floor($number * $factor) div $factor
  };
  local:floor($y, <value>15.2249348734</value>)
Hope this helps, Christian
Quoted text · George Sofianos · 18 lines
On Fri, Jan 13, 2017 at 2:16 PM, George Sofianos <gsf.greece at gmail.com> wrote: > Hi there, I was wondering if there is a similar function to format-number, > but without rounding, so I don't have to create a custom one that involves > string manipulation. > > For example I have two values: > let $x := <value>15.224134</value> > let $y := <value>15.2249348734</value> > > The following command will create different output for the two values > (result for $x will be 15.224, result for $y will be 15.225) > > format-number(xs:decimal($x), "0.000")) > > Thanks, > > George >

⚡Generated with XQuery