我正在根据公式计算两个数字之间的百分比增长
newnumber - oldnumber
----------------------- * 100
oldnumber
var oldNumber = 33, newNumber = 40;
var percent = newNumber - oldNumber;
var percent2 = percent/oldNumber;
var PercenIncr = Math.ceil(percent2*100).toFixed(2);
alert(PercenIncr)
http://jsfiddle.net/416jkaz7/2/
我可以在一行中完成所有这些操作吗?
最佳答案
尝试这个
var oldNumber = 33, newNumber = 40;
var PercenIncr = Math.ceil(((newNumber - oldNumber)/oldNumber)*100).toFixed(2);
alert(PercenIncr)