1

I'm using SharePoint 2007 and developing a custom view using SharePoint Designer 2007.

I've a column of a table that should display numbers as percentage. Minimun value is 0, maximum 100.

In SP Designer I'm using the suggested code:

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

But, unless I insert a number like 0 or 100, I always see "NaN". No default value is set.

Why?

2
  • format-number() expects a number, if you give it something else it will return NaN (Not a Number) error, what is the problem? Oct 21, 2013 at 13:17
  • Sorry, I mean if I insert "20" (without quotes, obviously), I see NaN. The value must be 0 or 100, but it is not correct.
    – Pepozzo
    Oct 21, 2013 at 13:27

2 Answers 2

2

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.

0

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%;-#')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.