带逗号的 XSLT 格式编号,用于印度价格 [英] XSLT format-number with comma for indian price

查看:22
本文介绍了带逗号的 XSLT 格式编号,用于印度价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示印度的价格,如下所示:

I want to display a price for India, like this:

5,55,555

而且不是

555,555

应该没有小数点.应该有一个逗号,像这样:

There should be no decimal. There should be a comma, like this:

  • 一千一千
  • 10,000 万
  • 1,00,000 十万

我的代码:

<Price>555555</Price>
<xsl:decimal-format name="Format_INR" grouping-separator="," />
<xsl:value-of select="format-number(Price, '#,##,###', 'Format_INR')" />

但它显示

555,555

我做错了什么?

感谢您的帮助.

推荐答案

如前所述,在 XSLT 2.0 中,您可以使用:

As already mentioned, in XSLT 2.0 you can use:

<xsl:value-of select="format-number(Price, '#,##,###')" />  

这最多可容纳 9,999,999 的数字.在此之上,您需要添加更多分隔符,例如:

This will accommodate numbers up to 9,999,999. Above that, you need to add more separators, e.g.:

<xsl:value-of select="format-number(Price, '##,##,##,###')" />      

适用于高达 999,999,999 等的数字.

will work for numbers up to 999,999,999 and so on.

XSLT 1.0 中,您可以:

<xsl:choose>
    <xsl:when test="Price >= 1000">
        <xsl:value-of select="format-number(floor(Price div 1000), '#,##')" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="format-number(Price mod 1000, '000')" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="format-number(Price, '#,###')" />
    </xsl:otherwise>
</xsl:choose>

这适用于任何幅度的Price.如果您需要重用它,请考虑将其设为命名模板.

This will work for any magnitude of Price. If you need to reuse this, consider making it a named template.

请注意,这两种方法都不需要您定义 xsl:decimal-format.

Note that neither method requires you to define a xsl:decimal-format.

这篇关于带逗号的 XSLT 格式编号,用于印度价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆