Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 2004-11-01
6
Medium Priority
?
476 Views
Last Modified: 2008-02-01
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
Comment
Question by:tjrobinson
  • 3
  • 2
6 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 12461624
Try:

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

Author Comment

by:tjrobinson
ID: 12461674
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
 
LVL 21

Accepted Solution

by:
MogalManic earned 1000 total points
ID: 12461684
Try:

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

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 

Author Comment

by:tjrobinson
ID: 12461701
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
 
LVL 21

Expert Comment

by:MogalManic
ID: 12461821
<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
 

Author Comment

by:tjrobinson
ID: 12461824
Thanks, that looks just the job.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question