C# Currency to string

MartGriff,

My best advice would be to convert it to a double using the SqlMoney type. From there, you can output it however you would like!

Here's an example:

System.Data.SqlTypes.SqlMoney ReturnValue;

//Set your returnValue with your SQL statement
ReturnValue = ExecuteMySqlStatement();

//Get the format you want

//$30.00
string currencyFormat = ReturnValue.ToDouble().ToString("c");

//30.00
string otherFormat = ReturnValue.ToDouble().ToString("0.00");

For more formatting options, check out the MSDN:

http://msdn.microsoft.com/en-us/library/system.double.tostring.aspx

Best of luck, I hope this helps.


You can use string format codes in your ToString call.


Do you want your string formatted using a currency character?

If so...

decimal m = 3.4;

string s = string.Format("{0:c}", m);

// s will be £3.40, $3.40, etc depending on your locale settings

Tags:

C#