problem with SUM function in XQuery


I have a big problem with formating a result of a SUM function. The result shouldn’t contain ‘E’ character.

let $z:=sum(input()/docs/floatvalue)
return $z

It gives for example: 123.45E4

how can I avoid such a situation and obtain a result like XXX.XX.

thanks in advance

please… any suggestions?

This is the way that Tamino prints large numbers (or doubles?), so I don’t think this problem has anything in particular to do with the sum() function. I don’t see any functions in tamino for formatting numbers, but you could probably use a stylesheet (XSL-FO) to process Tamino’s output into the form you want.




declare namespace xs=""
let $z:=sum(input()/docs/floatvalue)
return xs:integer($z)



This is a known gap in the current XQuery specs (which may or may not get filled - we’re having great trouble getting agreement in this area).

There’s no format-number capability in XQuery, but you can convert to an integer or decimal which will give you a more acceptable display. Or, of course, you can render the output through XSLT.

Michael Kay

Thanks you for all your answers :slight_smile:

The information that it’s “a gap in current xquery specification” satisfies my expectations :slight_smile: The worst situation is when I don’t know the solution that really exists.

I couldn’t use a stylesheet because I prepared a mechanism for different reports managed by one algoritm and XQuery is built “on fly”… so I don’t know a document structure… But it’s a more complex problem…

By the way do anybody explain me which function in XSLT can change this number format to normal double. Unfortunatelly format-number interprets this as a NaN (Not a Number).

Once again THANKS


I have another way of doing this.

Try inside the sum, doing the next:

1. Multiply * 100
2. Convert to integer
3. Divide / 100.