Ok, here's the thing. From DataTable
i read number_of_project and number_of_hours_per_day (most of time 5 to 7 hours per day). For each project i insert percentage_value with dynamically created TextBoxes
(Sum off all percentage_values is 100%). Formula for percentage must calculate hours_for_project_per_day.
double hours_for_project_per_day = percentage_value * number_of_hours_per_day / 100;
On the end i Round
hours_for_project_per_day. In many times calculation is right, but i get some non correct values (because of Rounding
) in case like this:
number_of_project = 5;
number_of_hours_per_day = 7;
percentage_value | project | (Math.Round)hours_for_project_per_day (double values)
-----------------|---------|------------------------------------------------------
30 | P1 | 2 (2,1)
17 | P2 | 1 (1,19)
18 | P3 | 1 (1,26)
20 | P4 | 1 (1,4)
15 | P5 | 1 (1,05)
-------------------------------------------
sum 100 | 5 | 6 (instead 7)
My question is: Can i do this some other way or just check if
if(sum_hours_for_project_per_day != number_of_hours_per_day)
and find hours_for_project_per_day with max decimal value (in this case 1,4) and put value 2?
Hope you know what i'm trying to do.