During run time I want to insert some integer value on textbox it should be display like currency format
example : 1000000 is input Expect 1,000,000.00
The below code is execute failure format
example 12345678 but actually i got 85,671,234 after first four(1234)integer the cursor automatically moved to backside
The code is
txtpurchasecost.Text = string.Format("{0:#,###,###.##}", double.Parse(txtpurchasecost.Text));
Thanks in Advance
答案 0 :(得分:0)
txtpurchasecost.Text = string.Format("{0:N2}", double.Parse(txtpurchasecost.Text));
and you may also specify the culture manually for the separators:
txtpurchasecost.Text = string.Format(
CultureInfo.CreateSpecificCulture("en-US"),
"{0:N2}",
double.Parse(txtpurchasecost.Text));
Also you can check this article: Standard Numeric Format Strings
答案 1 :(得分:0)
int temp = 0;
if (int.TryParse(txtpurchasecost.Text, out temp))
{
txtpurchasecost.Text = (int.Parse(txtpurchasecost.Text)).ToString("C2");
}
try this, this will fix your issue.