开发者

Need to express some numbers as percentages where the total of the numbers equals 1 not 100?

开发者 https://www.devze.com 2023-02-05 18:18 出处:网络
I need to express some numbers (for example, 1300, 500, 900) as a percentage where the total would be 1 not 100.

I need to express some numbers (for example, 1300, 500, 900) as a percentage where the total would be 1 not 100.

There could 10 numbers and the could be in the range of 1 to 99,999, I guess.

I need to do some maths in my program to convert these numbers into the appropriate values.

I'm probably not explaining this well.

Don't worry about the code, but heres what I need.

    [chart addSlicePortion:0.1 withName:@"Orange"];
    [char开发者_如何学Ct addSlicePortion:0.2 withName:@"Fandango"];
    [chart addSlicePortion:0.1 withName:@"Blue"];
    [chart addSlicePortion:0.1 withName:@"Cerulean"];
    [chart addSlicePortion:0.3 withName:@"Green"];
    [chart addSlicePortion:0.1 withName:@"Yellow"];
    [chart addSlicePortion:0.1 withName:@"Pink"];

I need to produce the number 0.1, 0.2 etc. Notice that they add up to 1


A normal percentage has a total of 1. If you have 1300, 500, and 900, add them up and then divide each by the total. 1300/(1300+500+900) for example. This will give you 0.48...


Divide each of the numbers by the total sum of all of the numbers. So,

1300 / (1300 + 500 + 900) = 0.48148148148148148148148148148148
500 / (1300 + 500 + 900) = 0.18518518518518518518518518518519
900 / (1300 + 500 + 900) = 0.33333333333333333333333333333333

Note that the sum of these numbers is

1300 / (1300 + 500 + 900) + 500 / (1300 + 500 + 900) + 900 / (1300 + 500 + 900) =
(1300 + 500 + 900) / (1300 + 500 + 900) =
1

You can also check this by adding the decimal expansions given.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号