It's not really clear what you mean by actual currency, but I'm assuming you just want a string that looks like the samples you've posted. Keep in mind that the decimal
type (the type best suited to represent currency) doesn't have any actual formatting information.
You'll have to parse the string
using decimal.Parse
, then convert the value back to a string
to get it into the desired format.
For example:
public string Format(string input)
{
decimal value = decimal.Parse(input);
return value.ToString("#,#.00");
}
// usage: Format("1000.0")
Example: https://dotnetfiddle.net/P7psPC
However if you're dealing with currency you can just use the C
format specifier:
value.ToString("C");
This would output the following for your sample inputs:
$80.00
$1,000.00
$1,000.00
($100.00)