将 double 型转换为不带小数位的字符串的最佳方法是什么?
String.valueOf((int) documentNumber) 怎么样?
double 在小数点后始终为 0。我不需要舍入或截断
最佳答案
如果您确定 double 确实是一个整数,请使用这个:
NumberFormat nf = DecimalFormat.getInstance();
nf.setMaximumFractionDigits(0);
String str = nf.format(documentNumber);
作为奖励,通过这种方式您可以将语言环境的配置保持为千位分隔符。
编辑
我添加了这个先前删除的选项,因为它似乎对 OP 很有用:
Double.valueOf(documentNumber).intValue();
关于java - 将double转换为不带小数位的String的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28707098/