Truncate decimal

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
 
G

Göran Andersson

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top