--------------------------
Fruit Trees
--------------------------
Apple 1098
Banana 500
Grapes 460
--------------------------
TOTAL 2058
--------------------------
Now, I want to find out, in form of percentage, how many trees are there for each fruit type. So, this is what I did
---------------------------------------------------------
Apple floor((1098*100)/2058) 53%
Banana floor(( 500*100)/2058) 24%
Grapes floor(( 460*100)/2058) 22%
---------------------------------------------------------
TOTAL 99%
As you can see, 1% is lost in flooring values
I need logic in a way that whatever the values are for each fruit, total should get to 100%.
Above one is SAMPLE DATA, number of tree for each fruit, and number of fruits can increase or decrease.
Just use
round()instead offloor()?But always be careful with adding rounded numbers or percentages. Better use the original values to calculate the total.