Percent of Total
EasyData EngineeringMathArray
Description
Given an array of numbers, return each value as a fraction of the sum of all values. If the total is 0, return all zeros. Round each result to 4 decimal places.
Examples
Input:
[1,1,2]Output:
[0.25,0.25,0.5]Explanation:
Dividing every value by the overall total expresses each one as its share of the whole.
Input:
[10,30,60]Output:
[0.1,0.3,0.6]Explanation:
Dividing every value by the overall total expresses each one as its share of the whole.
Input:
[5]Output:
[1]Explanation:
Dividing every value by the overall total expresses each one as its share of the whole.
Constraints
- •
1 ≤ length ≤ 10⁴