I am interested in how to round variables to two decimal places. In the example below, the bonus is usually a number with four decimal places. Is there any way to ensure the pay variable is always rounded to two decimal places?
pay = 200 + bonus;
Console.WriteLine(pay);
Pay attention on fact that
Round
rounds.So (I don't know if it matters in your industry or not), but:
To make it more precise for your case we can do something like this:
Use Math.Round and specify the number of decimal places.
Math.Round Method (Double, Int32)
Or Math.Round Method (Decimal, Int32)