sammy ben menahem
sammy ben menahem

Reputation: 33

rounding decimal number in linq

I have this line in code :

Avr_Hold_Time = (g.Sum(b => b.Field<int?>("QueueHoldCount")) == 0) 
                ? 0 
                : (double)(g.Sum(b => b.Field<int?>("Avr_Hold_Time"))) 
                  / (g.Sum(b => b.Field<int?>("QueueHoldCount")),

Which gives me floating number like 91.455678 I need to round up only 2 decimal after the point that rounds up after 3rd decimal number (e.g. 91.46) how can I do that ?

Upvotes: 0

Views: 9998

Answers (1)

Amir Popovich
Amir Popovich

Reputation: 29846

Use Math.Round:

decimal num = 91.455678m;
var rounded = Math.Round(num, 2); // 91.46

Upvotes: 2

Related Questions