Bangla Currency Format
string num="1045987609.5678";
txtSample.Text = BengaliCommaFormat(num);
//output 1,04,59,87,609.57
private string BengaliCommaFormat(string amount)
{
amount = Convert.ToDecimal(amount).ToString("0.00");
string minus = "";
if (amount.Substring(0, 1) == "-")
{
minus = amount.Substring(0, 1);
amount = amount.Substring(1, amount.Length - 1);
}
string[] amt = amount.Split('.');
string result = "";
result = "." + amt[1];
int len = amt[0].Length;
string temp;
if (len <= 3)
{
result = amt[0] + result;
}
else
{
result = amt[0].Substring(len - 3, 3) + result;
temp = amt[0].Substring(0, len - 3);
while (temp.Length > 0)
{
if (temp.Length < 3)
{
result = temp + "," + result;
temp = "";
}
else
{
result=temp.Substring(temp.Length - 2, 2) + "," + result;
temp = temp.Substring(0, temp.Length - 2);
}
}
}
return minus + result;
}
http://aksadur.blogspot.com/2016/01/bangla-currency-format.html
txtSample.Text = BengaliCommaFormat(num);
//output 1,04,59,87,609.57
private string BengaliCommaFormat(string amount)
{
amount = Convert.ToDecimal(amount).ToString("0.00");
string minus = "";
if (amount.Substring(0, 1) == "-")
{
minus = amount.Substring(0, 1);
amount = amount.Substring(1, amount.Length - 1);
}
string[] amt = amount.Split('.');
string result = "";
result = "." + amt[1];
int len = amt[0].Length;
string temp;
if (len <= 3)
{
result = amt[0] + result;
}
else
{
result = amt[0].Substring(len - 3, 3) + result;
temp = amt[0].Substring(0, len - 3);
while (temp.Length > 0)
{
if (temp.Length < 3)
{
result = temp + "," + result;
temp = "";
}
else
{
result=temp.Substring(temp.Length - 2, 2) + "," + result;
temp = temp.Substring(0, temp.Length - 2);
}
}
}
return minus + result;
}
http://aksadur.blogspot.com/2016/01/bangla-currency-format.html
Comments
Post a Comment