This article describes the method of calculating percentage values in Java. Share it for your reference. The specific implementation method is as follows:
public class Test1 { public static String myPercent(int y, int z) { String baifenbi = "";// Accept the value of percentage double baiy = y * 1.0; double baiz = z * 1.0; double fen = baiy / baiz; / / NumberFormat nf = NumberFormat.getPercentInstance(); Commented out is also a method // nf.setMinimumFractionDigits( 2 ); Keep to the few decimal places after the decimal point DecimalFormat df1 = new DecimalFormat("##.00%");// # #.00% // Percentage format, use 0 to make up for those with less than 2 digits // baifenbi=nf.format(fen); baifenbi = df1.format(fen); System.out.println(baifenbi); return baifenbi; } public static void main(String[] args) { myPercent(29,59); }}I hope this article will be helpful to everyone's Java programming.