android - 点后 2 位 float

我将在 android 中格式化 float ,点后有 2 位数字。 我搜索了一个示例,但我找不到。

谁能帮帮我。

最佳答案

float f = 2.3455f;  
String test = String.format("%.02f", f);

https://stackoverflow.com/questions/4391448/

相关文章:

java - String.format 或类似的正确格式字符串

eclipse - 有没有办法在 Eclipse 中手动折叠代码?

emacs - 在 Emacs 中,如何在一系列初始化语句中排列等号?

eclipse - 格式化后无法删除 Eclipse 中的 block 注释

formatting - 复制/粘贴到 Word 时如何保留 rstudio 的格式?

c#-3.0 - 如何在 Resharper 中更改 "Use Object Initializer

python - 从 Python 日期/时间获取 "2:35pm"而不是 "02:35PM"?

documentation - reStructuredText 中粗体字的一部分

coding-style - 线宽格式标准

c - 如何填充 printf 以考虑负号和可变长度数字?