js-newb
js-newb

Reputation: 513

XSLT format-number transform percent

Given the XML:

<current rate="0.1412" /> 

The desired output to screen is:

14.1200%

However, the current transform:

<xsl:value-of select="format-number(current/@rate, '###,##0.0000')"/>%

Yields the output:

0.1412%

Is it possible to do a format-number transform that will output a value in the desired format (four decimal places) given the current XML input or does it require a change in the xml input to better match the expected output?

Say:

<current rate="0.141200" />

Upvotes: 2

Views: 5096

Answers (2)

michael.hor257k
michael.hor257k

Reputation: 117083

There is no need to multiply or use any other tricks - just tell the format-number() function you want the number to be formatted as percent:

<xsl:value-of select="format-number(current/@rate, '#,##0.0000%')"/>

Upvotes: 7

Tim C
Tim C

Reputation: 70638

If your rate is being stored as a decimal, then you will need to multiple by 100 to show it as a percentage:

<xsl:value-of select="format-number(current/@rate * 100, '###,##0.0000')"/>%

Upvotes: 5

Related Questions