C#小数取上限2 [英] C# decimal take ceiling 2

查看:355
本文介绍了C#小数取上限2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的十进制值圆似2.2222至2.23。当我使用圆形,

I want to round my decimal value like 2.2222 to 2.23. When I use round,

decimal a = Math.Round((decimal)2.222, 2);

当我使用上限,这导致3

When I use ceiling, it cause 3

decimal c = Math.Ceiling((decimal)2.22);

我怎样才能得到2.2222至2.23?

How can I get 2.2222 to 2.23 ?

推荐答案

我解决我的问题。

 string n = "2.2222";
        string[] s = n.Split('.');

        if (s[1].Count() >= 3)
        {
            List<char> z = s[1].ToString().Take(2).ToList();
            int c=Convert.ToInt32(z[0].ToString() + z[1].ToString()) + 1;
          //  int b = Convert.ToInt32(s[1].ElementAt(0).ToString() + s[1].ElementAt(1).ToString()) + 1;
            string output= s[0] + "." + c.ToString();            
        }

现在任何数字可以把,这将需要2十进制值,并添加1.Thanks。

now any number can put ,it will take 2 decimal value and add 1.Thanks.

这篇关于C#小数取上限2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆