Mostrar "nan" en su lugar valor de porcentaje
-
10-12-2019 - |
Pregunta
Estoy usando SharePoint 2007 y desarrollar una vista personalizada utilizando SharePoint Designer 2007.
Tengo una columna de una tabla que debería mostrar números como porcentaje.El valor mínimo es 0, máximo 100.
en SP Designer Estoy usando el código sugerido:
<xsl:value-of select="format-number(@Probabilit_x00e0_, "###0,%;-###0,%", "lcid1040")" />
Pero, a menos que inserto un número como 0 o 100, siempre veo "Nan".No se establece ningún valor predeterminado.
¿Por qué?
Solución
You could capture the formatted number first and then check for a NaN value.
<xsl:variable name="myValue" select="format-number(@Probabilit_x00e0_, "###0,%;-###0,%", "lcid1040")" />
<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.
Otros consejos
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%;-#')