When displaying the value of a decimal currently with .ToString()
, it\'s accurate to like 15 decimal places, and since I\'m using it to represent dollars and ce
Mike M.'s answer was perfect for me on .NET, but .NET Core doesn't have a decimal.Round
method at the time of writing.
In .NET Core, I had to use:
decimal roundedValue = Math.Round(rawNumber, 2, MidpointRounding.AwayFromZero);
A hacky method, including conversion to string, is:
public string FormatTo2Dp(decimal myNumber)
{
// Use schoolboy rounding, not bankers.
myNumber = Math.Round(myNumber, 2, MidpointRounding.AwayFromZero);
return string.Format("{0:0.00}", myNumber);
}