Double类型,转百分数,代码如下:
public static String getPercentValue( double similarity){ NumberFormat fmt = NumberFormat.getPercentInstance(); fmt.setMaximumFractionDigits(2);//最多两位百分小数,如25.23% return fmt.format(similarity); }
Float类型,转百分数,代码如下:
public static String getPercentValue( float similarity){ NumberFormat fmt = NumberFormat.getPercentInstance(); fmt.setMaximumFractionDigits(2);//最多两位百分小数,如25.23% return fmt.format(similarity); }