Question Format the variable to Currency?

Gerald

Member
Joined
Dec 18, 2012
Messages
6
Programming Experience
Beginner
I am trying to add a double variable into a Console.WriteLine and am not sure to:
  1. Add into the Console.WriteLine command and
  2. Format the variable to Currency.



Any Help is greatly appreciated.
 
To convert a numeric value, or anything else for that matter, to a String, you call its ToString method. In the case of numeric types, you can pass a standard or custom format specifier to have the output formatted a particular way. To format a number as currency using the current culture, the format specifier is "c":
Console.WriteLine(myNumber.ToString("c"));
If you want to incorporate additional text then you can use the format specifier a slightly different way:
Console.WriteLine("Amount Due: {0:c}", myNumber);
 

Latest posts

Back
Top Bottom