Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前有一个Double应该显示货币的。然而,当 Double 实际显示时,它只显示这样的数据:“32.0”。我希望它采用“32.00”的格式。有没有办法修复 Double 的格式以及小数点后显示多少个数字?
Double
首先,不要使用双打来存储金额。请改用 BigDecimal。在处理金钱时,您不希望浮点运算固有的舍入错误。
其次,使用 java.text.DecimalFormat 格式化您的数字。