Here you can find the source of roundFormat(double d, int i)
public static String roundFormat(double d, int i)
//package com.java2s; /*//from w ww. j a va2s . c om * Copyright 2014-2024 the https://github.com/xiaoxing598/itganhuo. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * This project consists of JAVA private school online learning community group Friends co-creator [QQ group 329232140]. * ????JAVA???????????????????[QQ?329232140]; * See the list of IT dry technology sharing network [http://www.itganhuo.cn/teams]. * ???????????IT???????[http://www.itganhuo.cn/teams]; * The author does not guarantee the quality of the project and its stability, reliability, and security does not bear any responsibility. * ?????????????????????????????????????????. */ public class Main { public static String roundFormat(double d, int i) { String num = null; if (i == 1) { num = "0.0"; } if (i == 2) { num = "0.00"; } if (i == 3) { num = "0.000"; } if (i == 4) { num = "0.0000"; } if (i == 0) { num = "0"; } java.text.DecimalFormat df = new java.text.DecimalFormat(num); return df.format(d); } }