Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'decimal' does not contain a definition for 'Round'

Tags:

c#

new to C# and hit this compile error when attempting to use the Round method for the first time. 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();
}
like image 229
Nigel Foster Avatar asked Dec 13 '22 19:12

Nigel Foster


1 Answers

I bet you have .Net Core project version prior to 2.0. Decimal.Round() method was missing in .Net Core prior to 2.0 but is now available. 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.

like image 109
CodeFuller Avatar answered Dec 30 '22 14:12

CodeFuller