各位:
   字符串中全部是数字,如:478632.32,1677732424.48
   现在需求是这些字符串代表元,如何将上述字符串转化为万元单位的数字字串?四舍五入即可。
    即:47.8万元 167773.2万元有比较简便的方法么?迫求!

解决方案 »

  1.   

    ((double)xxx/10000).ToString("N1")+"万元";
      

  2.   

    int r = ((int)(478632.32 / 1000.00 + 0.5)) / 10.0;
      

  3.   

    楼上几个兄弟们有点害人,规矩点,用Round
      

  4.   

    兄好,2个问题:
    1.Round相较于Tostiring(“N1”),有何优越性?除了精度之外还有其他否?
    2.对于我的需求,Round能直接实现么?还是也需要除以10000.能否给个例子。
    拜谢!
      

  5.   

    来个兼容性比较强的,适合任意长度的小数,甚至超出double计算范围的:using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str1 = "1677732424.48";//一般长的
                string str2 = "1677211251251616735554.48";//二般长的
                string str3 = "1677732251251516624.4825125125125";//很长的
                //更长的            Console.WriteLine(Test(str1));
                Console.WriteLine(Test(str2));
                Console.WriteLine(Test(str3));            Console.Read();
            }
            static string Test(string input)
            {
                Regex regex = new Regex(@"^(?<wy>\d+)(?<qy>\d{4})+(|(.\d+))$", RegexOptions.IgnoreCase);
                Match m = regex.Match(input);
                if (m.Success)
                {
                    int qy = (int.Parse(m.Groups["qy"].Value) + 500) / 1000;
                    return string.Format("{0}.{1}", m.Groups["wy"].Value, qy);
                }
                else
                    throw new Exception("不是有效的字符串");
            }
        }
    }
      

  6.   


    这里为什么有个加500?菜鸟不懂!int qy = (int.Parse(m.Groups["qy"].Value) + 500) / 1000; 
      

  7.   

    商业运算要用Decimal
    Decimal.Round活Math.Round,查一下MSDN,干活不会没这个吧
    对于四舍五入微软有一些特别的解释