Hi,
OK. This is a very easy problem - that I can't find an answer for. I'm sure I'll fell dumb when I (you) figure it out.
I'm converting a string to currency. Nothing happens. It returns the same string - but not in catch - it is NOT going into catch.. Here's my function:
samples:
input:16406, 136.54
output: 16406, 136.54
public string currencyConvert(string money)
{
string curr ="";
try
{
curr = string.Format("{0:C}", money);
}
catch
{
curr = money;
}
return curr;
}
Loading
AlanPosted Jun 28, 2007, 12:37 PM
There's no need to be embarrassed, as this behaviour is not obvious :)
Incidentally, if you pass in a string which isn't numeric (let's say "123A.56"), then the TryParse()method will just make the 'number' variable zero and will give a return value of 'false'. I didn't try to catch this in my example by throwing an exception but you could, of course, do this if you wish.
IngridPosted Jun 28, 2007, 12:28 PM
Posted Jun 28, 2007, 11:40 AM
AlanPosted Jun 28, 2007, 11:30 AM
public string currencyConvert(string money)
{
decimal number;
decimal.TryParse(money, out number);
return string.Format("{0:C}", number);
}
Posted Jun 28, 2007, 11:24 AM