Formating a double value into a string

  • Thread starter Thread starter Daniel P.
  • Start date Start date
D

Daniel P.

How do I do this in C#?

// C++ and MFC code
double fMyValue = 17.25;
CString fMyValue;
fMyValue.Format( "%012.2f", fMyValue );

Thanks!
 
Daniel,

You can use the ToString method on the double structure to do this. The
documentation will specify the format options that are available to you.

Hope this helps.
 
I found that but
ToString( "000000000.00" );

looks a litle strange to me because I have to count the zeros by handle
while C++ has a more convenient way: "%012.2f"


Nicholas Paldino said:
Daniel,

You can use the ToString method on the double structure to do this. The
documentation will specify the format options that are available to you.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Daniel P. said:
How do I do this in C#?

// C++ and MFC code
double fMyValue = 17.25;
CString fMyValue;
fMyValue.Format( "%012.2f", fMyValue );

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top