如何将数字分解为百分比 (0 - 100%)?里面有详细信息

发布于 2024-08-31 11:02:22 字数 221 浏览 1 评论 0原文

我正在使用一个 JS 进度条,该进度条使用百分比设置:0 到 100(百分比)。当 160,000 人签署了某个表格时,我需要进度条达到 100%。我在 PHP 变量中设置了签名者总数,但不知道如何进行数学计算,将其转换为 1 - 100 范围内的百分比(这样进度条实际上反映了 160,000 的目标)。

我可能在这里遗漏了一些明显的东西(我对任何与数字相关的东西都很感兴趣)所以这里有人知道如何做到这一点吗?

I am using a JS progress bar that is set using a percentage: 0 to 100 (percent). I need the progress bar to reach 100% when 160,000 people have signed a certain form. I have the total number of signers set in a PHP variable but am lost on how to do the math to convert that into a percentage that fits within 1 - 100 (so that the progress bar actually reflects the goal of 160,000).

I may be missing something obvious here (i suck at anything number-related) so does anyone here have a clue as to how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冰火雁神 2024-09-07 11:02:23

只是

percentage = number/160000 * 100

Just

percentage = number/160000 * 100
贱贱哒 2024-09-07 11:02:23

如果 N 是目标,X 是迄今为止已签名的人数,则百分比为 (X/N)*100。

If N is the goal, and X is the number of people that have signed so far, then the percentage is (X/N)*100.

猛虎独行 2024-09-07 11:02:23

采取微软风格:

current = 12345
percentage = 100*(1-exp(-current/100000))

Do it Microsoft style:

current = 12345
percentage = 100*(1-exp(-current/100000))
陌路黄昏 2024-09-07 11:02:23

160,000/160,000 = 1 = 100%

160,000/2 = 0.5 = < code>50%

鉴于此,计算应该很容易。分子是已完成的数字,分母是“目标”——要完成的总数。

所以一旦你达到 80,000,你就完成了 50%,你的进度条也会这样呈现。

如果您需要使用较小的数字,请将所​​有内容除以 100 或 1000,这样您就可以减少相关庄园中数字的大小。

160,000 / 1000 = 160 160 将是您的分母。因此,50% 将为 80/160。这有道理吗?

160,000/160,000 = 1 = 100%

160,000/2 = 0.5 = 50%

Given this, the calculation should be easy. The numerator is the number completed and the denominator is the "goal" -- the total to complete.

So once you are 80,000 you'd be 50% complete and your progress bar would render as such.

If you need to work with smaller numbers, divide everything by 100 or 1000 and you can reduce the size of the numbers in a relevant manor.

160,000 / 1000 = 160 160 would be your denominator. So than 50% would be 80/160. Does this make sense?

电影里的梦 2024-09-07 11:02:23

...你不能将数字转换为百分比吗?

$percent = ($currentNumber / 160000) * 100; 

如果您不想要浮动答案,您可以根据需要进行转换或舍入。

...you can't convert a number to a percentage?

$percent = ($currentNumber / 160000) * 100; 

If you don't want a float answer you can just cast or round it however you'd like.

誰認得朕 2024-09-07 11:02:22

百分比计算是基础数学:

$total = 160000;
$current = 12345;
$percentage = $current/$total * 100;

Percentage calculation is basic mathematics:

$total = 160000;
$current = 12345;
$percentage = $current/$total * 100;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文