Hello fellow StackOverFlow, I am currently trying to do a multiplication of percentages %, but currently I have not been able to perform said operation,
Taking into account that it is a foreach
that loads me both inputs
.weight and .qualification as many times as there is a record, I need to do the following operation:
Rating * Weight + Rating * Weight + rating * weight and so on depending on the number of records that the cycle throws at me foreach
.
An example of data would be the following since I am working with percentages and decimals
Attached image for better understanding
My code is the following
@foreach (var item in ViewBag.listobjetivos)
{
<tr>
<td>@item.Nombre_Objetivo</td>
<td><input class="peso" type="text" value="@item.Peso_Objetivo" />%</td>
<td>@item.Descripcion_Objetivo</td>
<td><input class="calificacion" type="text" value='@string.Format("{0:F1}", item.calificacion)' /></td>
<td>@item.observacion</td>
</tr>
}
<span class="resultado"></span>
I need to multiply the weight which is a percentage % by the grade and the same for the other records but I need a total result of the sum of all
Here I leave you an image in excel so that you can understand me a little better, in the image you can see the operation in excel.
Example Rating: 1.5 * Weight: 5%, Result: 0.075
I remain attentive to any questions or news.
Edit answer:
.each
.suma_total
capture thosereturn
of the aforementioned functions.cantidad_filas
since in the image you show there are 5 rows but only 4 are full, that will depend on you, if you validate that the rows are empty or not.I hope my answer will help you
what is the reason why you want to do foreach ??