Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » easy way to format numbers to strings?
Closed Thread
Old 03-02-2009, 12:24 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default easy way to format numbers to strings?

In C#, I'd like to convert some numbers to strings in a standard format, but preferably in a simple way, such as if you were going to output them rather than store them in string variables, a la:
Code:
Console.WriteLine ("{0:F2}", num);
rather than use a bunch or string methods to make them all the same number of significant digits. Isn't there any way to do this?
BobLewiston is offline  
Old 03-02-2009, 02:11 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: easy way to format numbers to strings?

The code you wrote is using a string method inside Console.WriteLine(). You'll need to call String.Format() if you want to restrict the number of digits. Otherwise, you can call "ToString()" on the number.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On