Truncate decimal

  • Thread starter Thread starter Luigi Z
  • Start date Start date
L

Luigi Z

Hi all,
I have a decimal nullable variable that results from a division of other 2
decimal nullable variables (C# 2.0).
How can I "force" the result to have only 3 decimal?

For example

2/3 -> 0.66666666666666 -> 0.667

Thanks in advance
 
Luigi said:
Hi all,
I have a decimal nullable variable that results from a division of other 2
decimal nullable variables (C# 2.0).
How can I "force" the result to have only 3 decimal?

For example

2/3 -> 0.66666666666666 -> 0.667

Thanks in advance

Use the Round method in the Decimal class:

if (num.HasValue) {
num = Decimal.Round(num.Value, 3);
}
 
Back
Top