可以使用DecimalFormat类来保留两位小数。你可以按照以下方式修改代码:

final Long numberOfUsers = fromLaunchToSpecifiedMonth.get(companyEnumValue);
final Integer totalUserNumber = comMap.get(companyEnumValue);
double result = (double) numberOfUsers / totalUserNumber;

DecimalFormat df = new DecimalFormat("#.00");
String formattedResult = df.format(result);

System.out.println(formattedResult);

在这个示例中,我们将numberOfUserstotalUserNumber的类型转换为double,以便进行浮点数除法。然后,我们使用DecimalFormat类将结果格式化为保留两位小数的字符串。最后,我们打印出格式化后的结果

final Long numberOfUsers = fromLaunchToSpecifiedMonthgetcompanyEnumValue; final Integer totalUserNumber = comMapgetcompanyEnumValue; numberOfUserstotalUserNumber保留两位小数

原文地址: http://www.cveoy.top/t/topic/isga 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录