c#中货币专数值

[复制链接]
查看11 | 回复4 | 2009-8-14 13:50:01 | 显示全部楼层 |阅读模式
class Program{
static void Main(string[] args)
{
string x = "¥58.39999";
Console.WriteLine(ConvertToMoney(x));
}
static string ConvertToMoney(string money)
{
if (string.IsNullOrEmpty(money))
return null;
if (money.StartsWith("¥"))
{
try
{
decimal dec = Convert.ToDecimal(money.Substring(1));
decimal tmp = 100 * dec;
tmp = (decimal)((long)tmp);
dec = tmp / 100;
return dec.ToString(".00");
}
catch { return null; }
}
else
{
return null;
}
}} 不管你是"¥8","¥8.8","¥8.88"还是"¥8.888"都OK.
回复

使用道具 举报

千问 | 2009-8-14 13:50:01 | 显示全部楼层
s=Y85.888;s.ToString();s=s.SubString(2,s.length()-1);不知道有没有直接转换的库函数。
回复

使用道具 举报

千问 | 2009-8-14 13:50:01 | 显示全部楼层
string str = "¥85.888";str = str.ToString().Replace("¥", "");decimal c = Decimal.Parse(str);
回复

使用道具 举报

千问 | 2009-8-14 13:50:01 | 显示全部楼层
S = '¥85.888';S = S.Format(''%.2f',convert.todouble(S.SubString(2,s.length()-1)));感谢1楼~
回复

使用道具 举报

千问 | 2009-8-14 13:50:01 | 显示全部楼层
85.88==>("¥85.888".Replace("¥", string.Empty)).ToString("0.#0");
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行