Solved

formatnumber

Posted on 2010-09-02
7
583 Views
Last Modified: 2013-12-17
1799,
How can I show this number as 1.799

In classic asp i just write formatnumber()

How in c# ?
0
Comment
Question by:bongii
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33586972
have u tried tostring("N3") on your variable? you may need to divide by 1000
0
 
LVL 12

Accepted Solution

by:
w00te earned 500 total points
ID: 33586974
http://www.csharp-examples.net/string-format-double/
Examples of every type of formatting.  do {0:0.000} for yours.
// just two decimal places
String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 123.4);         // "123.40"
String.Format("{0:0.00}", 123.0);         // "123.00"
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33587002
or is this supposed to be the 1000th character?
0
3 Use Cases for Connected Systems

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

 
LVL 53

Expert Comment

by:Dhaest
ID: 33587086
http://msdn.microsoft.com/en-us/library/0c899ak8(v=VS.100).aspx
double value;



value = 123;

Console.WriteLine(value.ToString("00000"));

// Displays 00123



value = 1.2;

Console.WriteLine(value.ToString("0.00", CultureInfo.InvariantCulture));

// Displays 1.20

Console.WriteLine(value.ToString("00.00", CultureInfo.InvariantCulture));

// Displays 01.20

Console.WriteLine(value.ToString("00.00", 

                  CultureInfo.CreateSpecificCulture("da-DK")));

// Displays 01,20



value = .56;

Console.WriteLine(value.ToString("0.0", CultureInfo.InvariantCulture));

// Displays 0.6



value = 1234567890;

Console.WriteLine(value.ToString("#,#", CultureInfo.InvariantCulture));	

// Displays 1,234,567,890      

Console.WriteLine(value.ToString("#,#", 

                  CultureInfo.CreateSpecificCulture("el-GR")));	

// Displays 1.234.567.890      

Open in new window

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33587120
0
 

Author Comment

by:bongii
ID: 33587393
Thanks for the answers. I will try if it works and get back to you
0
 

Author Closing Comment

by:bongii
ID: 33594728
This is correct syntax:
{0:0,00}
0

Featured Post

3 Use Cases for Connected Systems

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now