round a number to the nearest tenth in csharp

You can use the Math.Round() method to round a decimal number to the nearest tenth.

Here's an example:

main.cs
decimal num = 10.3456m;
decimal roundedNum = Math.Round(num, 1); // round to 1 decimal place
93 chars
3 lines

The Math.Round() method takes two parameters: the first is the number you want to round, and the second is the number of decimal places to round to. In this example, we're rounding num to 1 decimal place, which means it will be rounded to 10.3.

gistlibby LogSnag