如何在JavaScript中计算百分比 由 podio发布于 2020-04-09 07:50:19 我正在编写瞄准训练器,用户可以击中或错过圆圈。 我想计算平均命中率/未命中率。 因此,例如用户: 点击次数:6次 和 未命中次数:3次 百分比是50%。 我想要它以100%,70%,60%的格式显示,是的,您知道了... 但是,如何通过计算达到这一目标呢?
查看是什么改变了点击和未命中字段的值。
Whenever there is a change in any of those fields, do
(hits/(hits+misses)) *100
to get the percentage.Also, take care in rounding off the percentage using
percentage.toFixed(2)
and add the%
sign after it or in the name of the field.希望能帮助到你。