110,566
社区成员
发帖
与我相关
我的任务
分享
decimal val = (decimal)Convert.ChangeType((new DataTable()).Compute("1/4", string.Empty), typeof(decimal));
static void Main(string[] args)
{
string temp = "1/4";
string[] arr = temp.Split('/');
decimal result = 0;
if (arr.Length > 1)
{
result = decimal.Parse(arr[0]) / decimal.Parse(arr[1]);
}
else if (arr.Length == 1)
{
result = decimal.Parse(arr[0]);
}
else
{
throw new System.Exception();
}
Console.WriteLine(result);
}