I'm attempting to convert a number value w/ 2 decimal places to a string with no decimal places. I read about format-number, and I thought this function was achieving my desired result, but in testing w/ the value 1.00 I was getting a 2 back. I read about some rounding issues in other threads, but all those had results that included decimals which I need mine not to and instead round to the nearest whole number. Please see my example below, and thank you so much in advance for your help.
<xsl:value-of select='format-number((1.00), "#")'/>
result = 2
I need the result to show 1. This seems so simple, but I'm obviously not understanding.
CodePudding user response:
First , format-number((1.00), "#"
does NOT return 2
in any XSLT processor I know of.
More importantly, you should not use format-number
to round numbers - esp. not in XSLT 1.0 where different processors can return different results. If you want to round a number to the nearest integer, use the provided round() function:
<xsl:value-of select="round('1.00')"/>
returns 1
.
If you only need to strip trailing zeros, then you can simply convert the input value to a number:
<xsl:value-of select="number('1.00')"/>
returns 1
.