Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

String.format with numbers less than zero

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hharry - 21 Feb 2008 18:12 GMT
Hello All,

I am using the following to format numbers precise to 2 decimal places
with thousand separators:

Double number = 100000.87;
string MyString = String.Format("{0:0,0.00}", number);
// 100,000.87
which is fine.

When the number is less than zero:
Double number = 0.8756;
string MyString = String.Format("{0:0,0.00}", number);
// 00.87
How do output 0.87 instead of 00.87 ?

Thanks in advance.
Alcides - 21 Feb 2008 18:27 GMT
Can try to use String.Format("{0:#,0.00}", number)
The "# " character will do it.

Alcides Schulz
http://alsql.blogspot.com
Claes Bergefall - 22 Feb 2008 10:17 GMT
string MyString = number.ToString("N2");

   /claes

> Hello All,
>
[quoted text clipped - 13 lines]
>
> Thanks in advance.
Ben Voigt [C++ MVP] - 22 Feb 2008 23:25 GMT
> Hello All,
>
[quoted text clipped - 13 lines]
>
> Thanks in advance.

Would you mind explaining when 0.8756 became less than zero?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.