package info.zoio.datatram;
import java.text.NumberFormat;
import java.text.ParseException;
public class DataTram {
//获取一个数值的百分比
public String FormatPercent(double number,int value){
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumIntegerDigits(value);
return nf.format(number);
}
//根据百分比获取数值
public double FormatNumber(String value){
double n = 0;
NumberFormat nf = NumberFormat.getPercentInstance();
try {
n = nf.parse(value).doubleValue();
} catch (ParseException e) {
// TODO: handle exception
}
return n;
}
public static void main(String[] args) {
DataTram dt = new DataTram();
String a = dt.FormatPercent(0.125789, 0);//13%
System.out.println(a);
double b = dt.FormatNumber(“50%”);//0.5
System.out.println(b);
}
}