十进制空格太多 [英] Too many decimal spaces
本文介绍了十进制空格太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将Math.Round或Ceiling添加到我的代码中以向上或向下舍入?
我将Excel文件导入Datagridview并进行数学计算。
How could I add Math.Round or Ceiling to my code to round up or Down?
I am importing an Excel file to a Datagridview and doing the math.
private void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow rows in dataGridView1.Rows)
{
int H = Convert.ToInt32(rows.Cells[7].Value ?? 0);
decimal I = Convert.ToDecimal(rows.Cells[8].Value ?? 0);
int L = Convert.ToInt32(rows.Cells[11].Value ?? 0);
var J = H == 0 ? 0: H * I / L;
rows.Cells[9].Value = J;
//ULD Stack =rounddown(106/S2,0)
decimal S = Convert.ToDecimal(rows.Cells[18].Value ?? 0);
int A = 106;
decimal T = A / S;
rows.Cells[19].Value = T;
//Stacks Wide =rounddown(96/R2,0)
int R = Convert.ToInt32(rows.Cells[17].Value);
int B = 96;
int U = B / R;
rows.Cells[20].Value = U;
//Stacks Day =roundup(J2/T2,0)
double j = Convert.ToDouble(rows.Cells[9].Value ?? 0);
double t = Convert.ToDouble(rows.Cells[19].Value ?? 0);
int V = (int)Math.Ceiling(Convert.ToDouble(j) / Convert.ToDouble(t));
rows.Cells[21].Value = V;
//Linear FT Stack =Q2/12
Decimal Q = Convert.ToInt32(rows.Cells[16].Value ?? 0);
var C = 12 ;
Decimal W = Q / C;
rows.Cells[22].Value = W;
//Raw Linear Ft Day =(V2*W2)/U2
int V21 = Convert.ToInt32(rows.Cells[21].Value ?? 0);
var W22 = Convert.ToDecimal(rows.Cells[22].Value ?? 0);
int U20 = Convert.ToInt32(rows.Cells[20].Value ?? 0);
var X = V21 == 0 ? 0 : V21 * W22 / U20;
rows.Cells[23].Value = X;}
我尝试了什么:
大量的研究试验,主要是错误。
What I have tried:
Lots of research trial and mostly error.
推荐答案
你可以得到这样的天花板
you can get ceiling like this
// Get ceiling of double value.
double value1 = 123.456;
double ceiling1 = Math.Ceiling(value1);
你可以阅读
Math.Round方法(系统)| Microsoft Docs [ ^ ]
and you can read
Math.Round Method (System) | Microsoft Docs[^]
using System;
public class Example
{
public static void Main()
{
Console.WriteLine("{0,5} {1,20:R} {2,12} {3,15}\n",
"Value", "Full Precision", "ToEven",
"AwayFromZero");
double value = 11.1;
for (int ctr = 0; ctr <= 5; ctr++)
value = RoundValueAndAdd(value);
Console.WriteLine();
value = 11.5;
RoundValueAndAdd(value);
}
private static double RoundValueAndAdd(double value)
{
Console.WriteLine("{0,5:N1} {0,20:R} {1,12} {2,15}",
value, Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero));
return value + .1;
}
}
这篇关于十进制空格太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文