Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

XSLT: What's wrong with <xsl:value-of select="format-number(Amount, "##.##")" />

I have the following data:

<Amount>40.0</Amount>

I want to display it as:

40.00

Using something along the lines of:

<xsl:value-of select="format-number(Amount, "##.##")" />

I get "XML Parsing Error: not well-formed" in Firefox. I can find examples where it shows the value of an attribute in this way or for a fixed value, but not the contents of a tag.
0
tjrobinson
Asked:
tjrobinson
  • 3
  • 2
2 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
Try:

<xsl:value-of select="format-number(Amount, '##.##')" />
0
 
tjrobinsonAuthor Commented:
That stops the error but I get an output of:

40

Probably something to do with the format parameter, I need to force the decimal places.
0
 
MogalManicCommented:
Try:

<xsl:value-of select="format-number(Amount, '#0.00')" />

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tjrobinsonAuthor Commented:
Thanks that works well. I've split the points between you, but before you go is there any way of stopping it displaying if it's non a number (NaN)?
0
 
MogalManicCommented:
<xsl:choose>
  <xsl:when test='String(Number(Amount))="NaN"'>
          0.00
  </xsl:when>
  <xsl:otherwise>
     <xsl:value-of select="format-number(Amount, '#0.00')" />
  </xsl:otherwise>
</xsl:choose
0
 
tjrobinsonAuthor Commented:
Thanks, that looks just the job.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now