Solved

Format string (double) in C#.

Posted on 2010-11-18
2
504 Views
Last Modified: 2013-12-17
Normally, I use this way to format a string in C#:
MainBoardImportBOMFG.Text = String.Format("{0:#,###.##}", Convert.ToDouble(myReader["FinishedGoodBOM"]));

If myReader["FinishedGoodBOM"] has value > 0, Ex: myReader["FinishedGoodBOM"] = 20000
MainBoardImportBOMFG.Text = 20,000
---> It's correct

But if  myReader["FinishedGoodBOM"] = 0 --> MainBoardImportBOMFG.Text = (nothing)
I want to display MainBoardImportBOMFG.Text = 0 when myReader["FinishedGoodBOM"] = 0
How can I do?

0
Comment
Question by:JameMeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
Mathiyazhagan earned 500 total points
ID: 34162716
use zero placeholder in your format string like :

            double dbl =10000;
            string ds =String.Format("{0:#,##0.00}", dbl);

if dbl = 1       then ds = 1.00
if dbl = 10     then ds = 10.00
if dbl = 100   then ds = 100.00
if dbl = 1000  then ds = 1,000.00
if dbl = 10000 then ds = 10,000.00
if dbl = 100000  then ds = 100,000.00
and if dbl = 0 then ds = 0.00

here we specifying # to custom holder and single 0 before . to display atleast one degit before .00
hope this helps
0
 

Author Closing Comment

by:JameMeck
ID: 34170260
Thanks! It's a perfect solution.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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