2009年4月21日 星期二

字串加上千分位符號

public static string decimalStringFormat(string Value)
{
string strValue = String.Empty;
try
{

if(Value == "0" || Value == "0.00")
strValue = "0.00";
else
strValue = decimalToString(Convert.ToDecimal(Value));
}
catch
{}
return strValue;
}



public static string decimalToString(decimal Value)
{
string strValue = String.Empty;
string str = Value.ToString();
if(str.Length > 3 && str.Substring(str.Length-3,1).Equals("."))
{
string[] objValue = Value.ToString().Split(new char[]{'.'});
strValue = Convert.ToDecimal(objValue[0]).ToString("##,###,###,###,###,###,###")+"."+objValue[1].ToString();
}
else
{
if(Value == 0)
strValue = "0.00";
else
strValue = Convert.ToDecimal(Value).ToString("##,###,###,###,###,###,###")+".00";
}
return strValue;
}

沒有留言:

張貼留言