我想要输出经纬度 double 值的字符串,小数点前有 1,2 或 3 位数字,小数点后有 7 位数字。如何在 java 中使用 DecimalFormat() 来做到这一点?
12.456789 should give 12.4567890
12.45678912 should give 12.4567891
提前致谢
最佳答案
尝试
String s = new DecimalFormat("00.0000000").format(12.456789);
这个版本具有固定的整数长度,或者
String s = new DecimalFormat("0.0000000").format(12.456789);
float 长度
关于java - 要求输出始终采用小数点右侧 2 位、左侧 7 位格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14242036/