Solved

Format string (double) in C#.

Posted on 2010-11-18
2
497 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
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now