easy way to format numbers to strings?

Status
Not open for further replies.

BobLewiston

In Runtime
Messages
182
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?
 
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.
 
Status
Not open for further replies.
Back
Top Bottom