numberformatnumberformat=numberformat.getpercentinstance();
051
s=numberformat.format(obj);
052
}else{
053
decimalformatdecimalformat=newdecimalformat(format);
054
s=decimalformat.format(obj);
055
}
056
}else{
057
numberformatnumberformat=numberformat.getinstance();
058
s=numberformat.format(obj);
059
}
060
}catch(exceptione){
061
}
062
returns;
063
}
064
065
**
066
*计算字符串四则运算表达式
067
*@paramstring
068
*@return
069
*
070
publicstaticstringputestring(stringstring){
071
stringregexcheck=“[\\(\\)\\d\\+\\-\\*\\.]*“;是否是合法的表达式
072
073
if(!pattern.matches(regexcheck,string))
074
returnstring;
075
076
matchermatcher=null;
077
stringtemp=““;
078
intindex=-1;
079
stringregex=“\\([\\d\\.\\+\\-\\*]+\\)“;提取括号表达式
080
string=string.replaceall(“\\s“,““);去除空格
081
try{
082
patternpattern=pattern.pile(regex);
083
循环计算所有括号里的表达式
084
while(pattern.matcher(string).find()){
085
matcher=pattern.matcher(string);
086
while(matcher.find()){
087
temp=matcher.group();
088
index=string.dexof(temp);
089
string=string.substring(0,index)
090
+putestirngnobracket(temp)
091
+string.substring(index+temp.length());
092
}
093
}
094
最后计算总的表达式结果
095
string=putestirngnobracket(string);
096
}catch(numberformatexceptione){
097
returne.getmessage();
(未完待续。).b