一、百分数转小数
Java中:
private float changePercentToPoint(String percent) {
return new Float(percent.substring(0, percent.indexOf("%"))) / 100;
}
js中:
function toPoint(percent){
var str=percent.replace("%","");
str= str/100;
return str;
}
二、小数转百分数
Java中
private String changePointToPercent(float point) {
return String.valueOf(point*100)+"%";
}
js中
/**
*这里需要先用Number进行数据类型转换,然后去指定截取转换后的小数点后几位(按照四舍五入),这里是截取一位,0.1266转换后会变成12.7%
*/
function toPercent(point){
var str=Number(point*100).toFixed(1);
str+="%";
return str;
}