Laksh
Laksh

Reputation: 151

XSL rounding issue

I have an XSL style sheet and I’m using format-number(xpath,"#,##0") to round the value. On my local machine the value 1006.5 gets rounded to 1007. However, the same style sheet on the server rounds 1006.5 to 1006.

Any idea why?

Upvotes: 2

Views: 354

Answers (2)

Giles
Giles

Reputation: 1424

I think this may be due to different XSLT 1.0 processors using different rounding methods (half-up vs round-to-even/banker's rounding). It might also be due to differences in the way floating point numbers are represented on different machines.

My answer to this question may provide more details and start you off on a solution (the solution there is for rounding to two decimal places, but perhaps you can see how it could be more generally applied).

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163595

In XSLT 1.0 the rounding rules for format-number() are under-specified. (In fact they are defined by reference to the JDK 1.1 specification, which is very hard to find nowadays, but I remember well that it was very underspecified).

Therefore, different XSLT 1.0 processors may behave differently.

XSLT 2.0 defines the rounding rules (though I forget exactly what they are).

Upvotes: 2

Related Questions