Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking with percentage in c#
    primarykey
    data
    text
    <p>Ok, here's the thing. From <code>DataTable</code> i read <strong>number_of_project</strong> and <strong>number_of_hours_per_day</strong> (most of time 5 to 7 hours per day). For each <strong>project</strong> i insert <strong>percentage_value</strong> with dynamically created <code>TextBoxes</code> (Sum off all <strong>percentage_values</strong> is 100%). Formula for percentage must calculate <strong>hours_for_project_per_day</strong>.</p> <pre><code> double hours_for_project_per_day = percentage_value * number_of_hours_per_day / 100; </code></pre> <p>On the end i <code>Round</code> <strong>hours_for_project_per_day</strong>. In many times calculation is right, but i get some non correct values (because of <code>Rounding</code>) in case like this:</p> <pre><code> 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) </code></pre> <p><strong>My question is:</strong> Can i do this some other way <strong>or</strong> just check if <code>if(sum_hours_for_project_per_day != number_of_hours_per_day)</code> and find <strong>hours_for_project_per_day</strong> with max decimal value (in this case 1,4) and put value 2? Hope you know what i'm trying to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload