我必须从DB2数据库中获取值并将其放入.txt文件中。
列的值是0.0000,但在.txt文件中,它的值是0E-4。
当我从数据库中获取值时,我将其转换为String数据类型,然后将其写入一个文件。
如何在.txt文件中打印0.0000?
发布于 2014-01-07 19:39:29
使用DecimalFormat
示例:
double value = 123456789.6666;
System.out.println(value);
DecimalFormat formatter_1 = new DecimalFormat("#,###.0000");
String stValue = formatter_1.format(value);
System.out.println(stValue);
DecimalFormat formatter_2 = new DecimalFormat("###.0000");
stValue = formatter_2.format(value);
System.out.println(stValue);输出:
1.234567896666E8
123,456,789.6666
123456789.6666 发布于 2014-01-07 19:31:43
如果price_from_db column声明为decimal(0,4),如果数据库中没有值,则默认情况下将考虑0.0000。
发布于 2014-02-12 11:08:27
Bigdecimal price;如果此值以指数格式来自DB,则设置为0E-11
我们可以在java代码中使用price.toPlainString()来获得类似于0.00000000000的值
对我有效!!
https://stackoverflow.com/questions/20970256
复制相似问题