Skip to content

Commit 0f826bd

Browse files
committed
fix: round hours played to 2 decimals before updating total
Rounds the HoursPlayed value to two decimal places when updating the tester's total playtime. This change ensures: - Avoiding unnecessarily long decimal precision. - Making the total hours more readable for clients (e.g., 7.25h instead of 7.251237h). - Preventing floating-point accumulation errors when summing many small fractions of hours.
1 parent e17722f commit 0f826bd

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/UseCases/Testers/UpdatePlaytime.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ public async Task<Result> ExecuteAsync(string accessKey, UpdatePlaytimeRequest r
2828
if (validationResult.IsFailed())
2929
return validationResult.Invalid();
3030

31+
double roundedHours = Math.Round(request.HoursPlayed, 2);
3132
int affectedRows = await dbContext
3233
.Set<Tester>()
3334
.Where(t => t.AccessKey == accessKey)
3435
.ExecuteUpdateAsync(setters => setters
35-
.SetProperty(t => t.TotalHoursPlayed, t => t.TotalHoursPlayed + request.HoursPlayed));
36+
.SetProperty(t => t.TotalHoursPlayed, t => t.TotalHoursPlayed + roundedHours));
3637

3738
return affectedRows == 0 ? Result.NotFound() : Result.Success();
3839
}

0 commit comments

Comments
 (0)