我正在使用SharePoint 2007并使用SharePoint Designer 2007开发自定义视图。

我是一列表,应该将数字显示为百分比。最小值为0,最多100。

在SP Designer中,我正在使用建议的代码:

<xsl:value-of select="format-number(@Probabilit_x00e0_, &quot;###0,%;-###0,%&quot;, &quot;lcid1040&quot;)" />
.

但是,除非我插入0或100等数字,否则我总能看到“nan”。没有设置默认值。

为什么?

有帮助吗?

解决方案

You could capture the formatted number first and then check for a NaN value.

<xsl:variable name="myValue" select="format-number(@Probabilit_x00e0_, &quot;###0,%;-###0,%&quot;, &quot;lcid1040&quot;)" />
<xsl:choose>
  <xsl:when test="string(number($myValue))='NaN'">0</xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$myValue" />
  </xsl:otherwise>
</xsl:choose>

This will switch out NaN for a zero.

其他提示

When using "format-number", it expects a period separator for decimals. With the percentage field (LCID 1036 for french), the decimals separator is a comma.

I had to translate the comma to get it working correctly. I haven't checked if it is the same thing for 1033 or 1040 in this case.

format-number(string(translate(@PercentField,',','.')), '#,##0%;-#')
许可以下: CC-BY-SA归因
scroll top