[英]JavaScript - Incorrect division
perc = 15/30;
//result=Math.round(perc*100)/100 //returns 28.45
$('#counter').text(perc);
$('#total').text(count);
returns back 0.5%
which is suppose to be 50.00%
... how do I fix this? 返回
0.5%
,这假设是50.00%
...我该如何解决这个问题? :S :S
You do realize that word percent quite literally translates into "per cent" or "per 100" since cent is the latin root that's used everywhere meaning "100" or "one-hundredth". 你确实意识到单词百分比完全可以翻译成“百分比”或“每100”,因为分数是拉丁语根,在任何地方使用意味着“100”或“百分之一”。
So 50% becomes 50 per cent becomes 50 per 100 所以50%变为50%变为50每100
And, since in mathematical terms, the word per means divide (miles per hour == mph == m/h) then we can distill 50% down to: 并且,因为在数学术语中,单词per表示除以 (英里每小时== mph == m / h)然后我们可以将50%提取到:
50/100
50/100
Which, surprisingly enough, is represented as the decimal number .5 令人惊讶的是,它以十进制数表示.5
15/30 = 0.5 15/30 = 0.5
if you want to have percent number you have to multiply it by 100. 如果你想拥有百分比数字,你必须乘以100。
I am a low rep user so here goes. 我是一个低代表用户,所以这里。 http://en.wikipedia.org/wiki/Percentage
http://en.wikipedia.org/wiki/Percentage
Treat the % sign as a constant equal to 0.01. 将%符号视为等于0.01的常量。 Thus, when working with a number like
50%
, treat it as 50 * 0.01
or 0.5
. 因此,当使用
50%
的数字时,将其视为50 * 0.01
或0.5
。
0.5 = n % // I want to know what 0.5 is as a percent 0.5 / % = n * % / % // Divide both sides by the constant 0.5 / % = n // Remove the excess 0.5 / 0.01 = n // Replace the constant 50 = n // You have your answer
只需乘以100即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.