Reputation: 35
output string (for example) is "12,236,15". I cannot change into the system format or type string.
Expected result: 12356.15
I use:
<xsl:value-of select="format-number(translate('12,236,15', ',','.'), '#.00')"/>
It works well with strings containing just one 'comma' symbol. Can I change just one symbol to 'dot' from the end?
The end can come as '12,236,156' (with 3 numbers), so fixed substring doesn`t match.
Upvotes: 0
Views: 393
Reputation: 117102
I want to clarify is it possible or this is the bug and another department should fix it first.
Both. Using a comma for both the decimal and the thousands separator is definitely not a good way to represent a number.
Still, this seems to be working in XSLT 2.0:
<xsl:variable name="number" select="replace(input, ',(\d*)$', '.$1')" />
<xsl:variable name="number" select="translate($number, ',', '')" />
<xsl:value-of select="format-number($number, '#.00')"/>
Demo: https://xsltfiddle.liberty-development.net/pPzifp4
Upvotes: 1