Java Double to String conversion without formattin

2019-01-15 05:42发布

I have the number 654987. Its an ID in a database. I want to convert it to a string. The regular Double.ToString(value) makes it into scientific form, 6.54987E5. Something I dont want.

Other formatting functions Ive found checks the current locale and adds appropriate thousand separators and such. Since its an ID, I cant accept any formatting at all.

How to do it?

[Edit] To clarify: Im working on a special database that treats all numeric columns as doubles. Double is the only (numeric) type I can retrieve from the database.

9条回答
forever°为你锁心
2楼-- · 2019-01-15 06:00

Also you can use

double value = getValue();

NumberFormat f = NumberFormat.getInstance();
f.setGroupingUsed(false);

String strVal = f.format(value);
查看更多
在下西门庆
3楼-- · 2019-01-15 06:08

What about Long.toString((long)value) ?

查看更多
神经病院院长
4楼-- · 2019-01-15 06:09
    double d = 56789;
    String s = d+"";
查看更多
登录 后发表回答