代码之家  ›  专栏  ›  技术社区  ›  Rohit Azad Malik

如何将以百万为单位的金额转换为XSLT中的十进制值

  •  0
  • Rohit Azad Malik  · 技术社区  · 7 年前

    我有这样的产品价目表 Rs 148573769277.60 (Rs 14857.38 crores) 在XSLT中。

    如果我有数量 818354941.60 那么我想换成这个 81.84卢比 ( Indian numbering system )

    如何在XSLT中执行此操作?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Christian Mosz    7 年前

    我想你在找这样的东西:

    <fo:block>
        <xsl:variable name="orignumber" select="'Rs 148573769277.60'"/>
        <!-- filter only the numbers and the '.' from the text -->
        <xsl:variable name="number" select="translate($orignumber, translate($orignumber, '0123456789,.', ''), '')"/>
        <!-- this sets the format to 2 decimals - the multiplication is based on your text. -->
        <!-- concat just adds your chosen text(unit) to the number/string -->
        <xsl:value-of select="concat('Rs ', format-number(number($number) * 0.0000000001,'##.##'), ' (Crores)')"/>
    </fo:block>
    

    或者,您可以只过滤数字并自己设置“.”。