c# - C#如何通过多次停止小数移位
问题描述
我创建了一个表格来安排船舱。
问题:多次返回时,小数点又移动了两个空格。我如何防止它进一步移动?
代码片段:
private void btnGetInv_Click(object sender, EventArgs e)
{
//if this is a ship hold, roll percentile to get how much of the ship's total weight capacity is being carried.
if(ShipHold==true)
{
decimal Percentage = 0;
decimal HoldWeight = 0;
LoNum = 1;
HiNum = 100;
DieResult = 0;
Percentage = DieResult + 1 + RollDice.Next(LoNum - 1, HiNum);
WeightAvail = Percentage / 100 * WeightAvail;
HoldWeight = WeightAvail;
RTBItems.Text = "percentage of weight = " + HoldWeight + "\r\n" + RTBItems.Text;
}
WeightAvail
也是一个decimal
。然而; LoNum
, HiNum
, 和DieResult
都是int
使用该Random.Next
函数的类型。如果我可以四舍五入到最接近的整数可能是最好的。我正在使用 Visual Studio 2019。
这是我的修复:
HoldWeight = Percentage / 100 * WeightAvail;
//HoldWeight = WeightAvail;
RTBItems.Text = "percentage of weight = " + HoldWeight + "\r\n" + RTBItems.Text;
HoldWeight = 0;
解决方案
推荐阅读
- python - django 聚合 SUM 是否缓存?还是每次都计算?
- javascript - 我可以通过 JavaScript 以编程方式打开浏览器的本机搜索对话框吗?
- amazon-web-services - kubernetes 的保险库(保险库操作员)
- javascript - 现在如何知道在 SHAKA PLAYER 中传递 ContentProtectionCallback?
- wpf - Catel:Treeview HierarchicalDataTemplate
- swift - 如何设置全屏视图框架(包括导航栏和状态栏)?
- matlab - 使用 xlswrite 提取两列中的结果
- javascript - 使用动态路径更新猫鼬
- nginx - uwsgi 和 nginx 上游的 Web2py 在读取上游时超时(110:连接超时)
- javascript - Javascript JQuery警报弹出窗口未显示