Formatting numbers, excluding trailing zeroes

后端 未结 2 1449
情深已故
情深已故 2021-01-16 23:35

first time SO user :)

I know that I can format a number like this:

format-number($value, \'###,###.00\')

But I would like to remove

相关标签:
2条回答
  • 2021-01-17 00:11
    format-number($value, '###,###.##')
    
    0 讨论(0)
  • 2021-01-17 00:11

    xpath 2.0 contains conditional logic if..then..else but in the more likely case that you're in xpath 1.0 I'm afraid you'll have to either rely on XSLT to do this for you, i.e:

    <xsl:variable name="myvar">
      <xsl:choose>
        <xsl:when test="$value > 0">
          <xsl:select="format-number($value, '###,###.00')"/>
        </xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>>
    </xsl:variable>
    

    ..or mixin an extension (.NET can do this natively, EXSLT exists otherwise, probably more options available)

    To the best of my knowledge no xpath functions exist to get you out of this, but I could be missing something exotic.

    0 讨论(0)
提交回复
热议问题