Java将小数转换成百分数

import java.text.NumberFormat;
public static void main(String[] args) {
        int i = 123;
        int ii = 1234;

        NumberFormat num = NumberFormat.getPercentInstance();
        num.setMaximumIntegerDigits(3);
        num.setMaximumFractionDigits(2);

        System.out.println(num.format((double)i / ii));
    }
输出结果为: 9.97%

你可能感兴趣的:(Java)