Solved

Format string (double) in C#.

Posted on 2010-11-18
2
506 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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