Java:将double转换为String [英] Java: Converting a double to a String
问题描述
我有一个双倍,其值为10,000,000.00(一千万)。我必须将
转换为 String
。当使用方法 toString
我得到字符串
1.0E7这是符合规范的。不幸的是,我需要
字符串
10,000,000.00(或等效的,具体取决于区域设置)。
I have a double whose value is 10,000,000.00 (ten millions). I have to
convert it to a String
. When using the method toString
I am getting the String
"1.0E7" which is correct following the specification. Unfortunately I need
the String
"10,000,000.00" (or the equivalent depending on the locale).
如何实现这个目标?
推荐答案
尝试
NumberFormat http://java.sun.com/javase/6/docs /api/java/text/NumberFormat.html
NumberFormat http://java.sun.com/javase/6/docs/api/java/text/NumberFormat.html
DecimalFormat http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html
DecimalFormat http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html
这篇关于Java:将double转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!