Skip to content

Commit 23be81e

Browse files
Fix remote AVG over Double / Float (#325)
1 parent 67d806a commit 23be81e

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

net/DevExtreme.AspNet.Data.Tests/RemoteGroupingTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ public void Summary_Average_EmptyWithZeroSum() {
352352
Assert.Null(result.Totals[0]);
353353
}
354354

355+
[Fact]
356+
public void Issue324() {
357+
var loadResult = DataSourceLoader.Load(new float?[] { 1, 3 }, new SampleLoadOptions {
358+
RemoteGrouping = true,
359+
TotalSummary = new[] {
360+
new SummaryInfo { Selector = "this", SummaryType = "avg" }
361+
}
362+
});
363+
364+
Assert.Equal(2d, loadResult.summary[0]);
365+
}
366+
355367
}
356368

357369
}

net/DevExtreme.AspNet.Data/RemoteGrouping/RemoteAvgAggregator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DevExtreme.AspNet.Data.Aggregation {
77

88
class RemoteAvgAggregator<T> : Aggregator<T> {
99
Aggregator<T> _countAggregator;
10-
Aggregator<T> _valueAggregator;
10+
SumAggregator<T> _valueAggregator;
1111

1212
public RemoteAvgAggregator(IAccessor<T> accessor)
1313
: base(accessor) {
@@ -21,11 +21,13 @@ public override void Step(T container, string selector) {
2121
}
2222

2323
public override object Finish() {
24-
var count = (decimal?)_countAggregator.Finish();
24+
var count = Convert.ToInt32(_countAggregator.Finish());
2525
if(count == 0)
2626
return null;
2727

28-
return (decimal?)_valueAggregator.Finish() / count;
28+
var valueAccumulator = _valueAggregator.GetAccumulator();
29+
valueAccumulator.Divide(count);
30+
return valueAccumulator.GetValue();
2931
}
3032
}
3133

0 commit comments

Comments
 (0)