C# Developers' Journal (original) (raw)
6:17p
public static string FormatMoney(string val, bool showDollarSign){
decimal decVal;
if(val == "") return "";
try{
decVal = Decimal.Parse(val.ToString());
}
catch{
return "Invalid";
}
decVal = decimal.Round(decVal, 2);
if(showDollarSign){
return "$" + decVal.ToString();
}
else{
return decVal.ToString();
}
}
Can anyone fix for me? I'm sure there was something out there that does this but I couldn't find it so I wrote that. Only issue is that sometimes if it's like 7.60 it displays at $7.6.
Thanks.