我想用数学来做。圆的函数
当前回答
这是为了在c#中四舍五入到小数点后2位:
label8.Text = valor_cuota .ToString("N2") ;
在VB。NET:
Imports System.Math
round(label8.text,2)
其他回答
Math.Floor(123456.646 * 100) / 100 会返回123456.64吗
public double RoundDown(double number, int decimalPlaces)
{
return Math.Floor(number * Math.Pow(10, decimalPlaces)) / Math.Pow(10, decimalPlaces);
}
试试这个:
twoDec = Math.Round(val, 2)
我知道这是一个老问题,但请注意数学轮和字符串轮之间的以下区别:
decimal d1 = (decimal)1.125;
Math.Round(d1, 2).Dump(); // returns 1.12
d1.ToString("#.##").Dump(); // returns "1.13"
decimal d2 = (decimal)1.1251;
Math.Round(d2, 2).Dump(); // returns 1.13
d2.ToString("#.##").Dump(); // returns "1.13"
下面是一些例子:
decimal a = 1.994444M;
Math.Round(a, 2); //returns 1.99
decimal b = 1.995555M;
Math.Round(b, 2); //returns 2.00
你可能还想看看银行家的四舍五入/四舍五入到偶数与以下过载:
Math.Round(a, 2, MidpointRounding.ToEven);
这里有更多的信息。
推荐文章
- 何时使用IList,何时使用List
- ConfigurationManager。AppSettings在.NET Core 2.0中可用?
- 在c#的控制台应用程序中使用'async
- 在单元测试中设置HttpContext.Current.Session
- 如何开始开发Internet Explorer扩展?
- 更新行,如果它存在,否则插入逻辑实体框架
- 在什么情况下SqlConnection会自动被征召到环境事务范围事务中?
- 用c#解析JSON
- Windows窗体中的标签的换行
- 为什么在c#中使用finally ?
- 为什么我不能在c#中有抽象静态方法?
- net HttpClient。如何POST字符串值?
- 我如何使一个方法的返回类型泛型?
- 何时处理CancellationTokenSource?
- 如何获取正在执行的程序集版本?