Math 需要将一些数字表示为百分比,其中数字总数等于1而不是100?

Math 需要将一些数字表示为百分比,其中数字总数等于1而不是100?,math,expression,Math,Expression,我需要将一些数字(例如,1300500900)表示为一个百分比,其中总数是1而不是100 可能有10个数字,我想可能在1到99999之间 我需要在我的程序中做一些数学运算,将这些数字转换成适当的值 我可能没解释清楚 不要担心代码,但这是我需要的 [chart addSlicePortion:0.1 withName:@"Orange"]; [chart addSlicePortion:0.2 withName:@"Fandango"]; [chart addSlicePo

我需要将一些数字(例如,1300500900)表示为一个百分比,其中总数是1而不是100

可能有10个数字,我想可能在1到99999之间

我需要在我的程序中做一些数学运算,将这些数字转换成适当的值

我可能没解释清楚

不要担心代码,但这是我需要的

    [chart addSlicePortion:0.1 withName:@"Orange"];
    [chart 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"];

我需要生成数字0.1、0.2等。请注意,它们加起来等于1

正常百分比总共为1。如果有1300、500和900,将它们相加,然后除以总数。例如,1300/(1300+500+900)。这将为您提供0.48…

将每个数字除以所有数字的总和。所以

1300 / (1300 + 500 + 900) = 0.48148148148148148148148148148148
500 / (1300 + 500 + 900) = 0.18518518518518518518518518518519
900 / (1300 + 500 + 900) = 0.33333333333333333333333333333333
请注意,这些数字的总和为

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

您也可以通过添加给定的十进制展开式来检查这一点。

Erm,我需要将每一个表示为百分比,但用0表示。不管您使用什么数字,如果将它们全部相加,然后除以总数,那么总数将始终为1。