如何在Java中格式化一个带有小数点后给定位数的浮点数?
Java中从浮点中获取字符串的最佳方法是什么,该字符串在点后仅包含X个数字?
What is the best way in Java to get a string out of a float, that contains only X digits after the dot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有两种处理该问题的方法。
Here are two ways of dealing with the problem.
注意:
%n
用于换行来源: http://download.oracle.com/javase/tutorial/java/data/numberformat.html
note:
%n
is for newlineSource: http://download.oracle.com/javase/tutorial/java/data/numberformat.html
是
Float.toString ()
你在追求什么?另请参阅
Formatter
类的替代方法。Is
Float.toString()
what you're after?See also the
Formatter
class for an alternative method.