简体   繁体   English

'decimal'不包含'Round'的定义

[英]'decimal' does not contain a definition for 'Round'

new to C# and hit this compile error when attempting to use the Round method for the first time. C#的新手,并在第一次尝试使用Round方法时遇到此编译错误。 Any ideas? 有任何想法吗? Thanks: 谢谢:

private void totalPoundsTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    TextBox textBox = textBoxes[1];
    decimal numericValue = textBoxNumberCheck(textBox, 0M, 22046M,false);
    if (numericValue >= 0)
        ***weight.Kilos =  decimal.Round(numericValue / 2.2046M, 2, MidpointRounding.AwayFromZero);***
        UpdateBoxValues();
}

I bet you have .Net Core project version prior to 2.0. 我敢打赌你有2.0之前的.Net Core项目版本。 Decimal.Round() method was missing in .Net Core prior to 2.0 but is now available. 在2.0之前的.Net Core中缺少Decimal.Round()方法,但现在可用了。 Check this issue for the details. 请查看此问题以获取详细信息。

So you could fix your problem either by upgrading to .Net Core 2.0 or by using Math.Round() as Sunil suggests. 因此,您可以通过升级到.Net Core 2.0或使用Math.Round()来解决您的问题,正如Sunil建议的那样。

Use Math.Round instead: 请改用Math.Round

private void totalPoundsTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    TextBox textBox = textBoxes[1];
    decimal numericValue = textBoxNumberCheck(textBox, 0M, 22046M,false);
    if (numericValue >= 0)
        weight.Kilos = Math.Round(numericValue / 2.2046M, 2, MidpointRounding.AwayFromZero);

    UpdateBoxValues();
}

请改用Math.Round。

weight.Kilos = Math.Round(numericValue / 2.2046, 2, MidpointRounding.AwayFromZero);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM