1. 转百分比
java控制器 json转百分比
NumberFormat number = NumberFormat.getPercentInstance();
number.setMaximumFractionDigits(0);//设置小数点后几位
double answerDurPre20Double = Double.parseDouble(vo.getAnswerDurPre20());
String answerDurPre20 =number.format(answerDurPre20Double);
vo.setAnswerDurPre20(answerDurPre20);
NumberFormat number = NumberFormat.getPercentInstance();
number.setMaximumFractionDigits(0);//设置小数点后几位
double goodProportionDouble = Double.parseDouble(obj.get("messageProportion").toString()); //转化为double
// int messageProportionInt = Integer.parseInt(obj.get("messageProportion").toString());
String messageProportion =number.format(goodProportionDouble);
exportData.setDxcyprecent(messageProportion);
dxcyprecent:Math.round(obj.messageProportion*100).toFixed(2)+"%",
js中 转百分比
//百分数转化为小数
//1.先去掉百分号
//2.再除以100
//3.返回出去
var percent = "4.2%";//申明要放在函数前
function toPoint(percent){
var str=percent.replace("%","");
str= str/100;
return str;
}
toPoint(percent);
var result = toPoint(percent);
document.write(result);//0.042
//小数转化为分数
//1.先转化为number类型
//2.再乘以100
//3.保留小数位
var point = 0.042;
function toPercent(point){
var percent = Number(point*100).toFixed(1);
percent+="%";
return percent;
}
var result = toPercent(point);
document.write("<br/>"+result);
2.转int
js中 转int
var ss=parseInt(list[i].count1)+Number(list[i].count2);
parseInt 和Number 都可以
区别 var str1=‘00100‘;
alert( Number(str1) ); //得到100
alert(parseInt(str1)); //得到64 parseInt方法在format‘00‘开头的数字时会当作2进制转10进制的方法进行转换
java 控制器 String str =
"123"
;
int
a = Integer.parseInt(str);
int
b = Integer.valueOf(str).intValue()
;
3....
原文地址:https://www.cnblogs.com/gzl180110/p/10929297.html