I'm writing a banking system and my customer wants support both Russian and American numeric standards in decimal digits delimiter. Respectively .
and ,
.
Now only ,
works properly. Perhaps because of web server's OS format (Russian is set).
String like 2000.00
throws a FormatException
:
Input string was not in a correct format.
How to fix that? I have next two ideas:
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
var txtAmount = (TextBox)((FormView)sender).FindControl("txtAmount"));
txtAmount.Text = txtAmount.Text.Replace('.', ',');
}
or
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
var ru = new CultureInfo("ru-RU");
var en = new CultureInfo("en-US")
decimal d;
var txtAmount = (TextBox)((FormView)sender).FindControl("txtAmount"));
if (!Decimal.TryParse(value, NumberStyles.Any, ru, out d)
&& Decimal.TryParse(value, NumberStyles.Any, en, out d)
{
// data isn't in Russian format but is in American
txtAmount.Text = d.ToString(ru);
}
}
Are there any other ideas?