JDBC:jtds getString() 以科学记数法返回双精度数

发布于 2025-01-02 00:47:20 字数 536 浏览 2 评论 0原文

使用 jtds JDBC 驱动程序时,getString 有时会返回以科学记数法格式化的双精度数:

// metaData.getColumnType(0) == java.sql.Types.DOUBLE
String.format("%f", resultSet.getDouble(0)); // = 26150279.910000
resultSet.getString(0);  // = 2.615027991E7

对于某些值则不会:

String.format("%f", resultSet.getDouble(0)); // = 624000.000000
resultSet.getString(0);  // = 624000.0

是否可以强制 getString 始终返回 %f-格式的双打?

请不要说服我使用getDouble()。谢谢。

When using jtds JDBC driver, getString sometimes returns doubles formatted in the scientific notation:

// metaData.getColumnType(0) == java.sql.Types.DOUBLE
String.format("%f", resultSet.getDouble(0)); // = 26150279.910000
resultSet.getString(0);  // = 2.615027991E7

for some values it doesn't:

String.format("%f", resultSet.getDouble(0)); // = 624000.000000
resultSet.getString(0);  // = 624000.0

Is it possible to force getString to always return %f-formatted doubles?

Please, don't persuade me to use getDouble(). Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2025-01-09 00:47:20

使用 getDouble 提取双精度数:

double num = resultSet.getDouble();

创建一个十进制格式化程序,指定要使用的模式。如果您不指定它,则使用默认的语言环境模式:

DecimalFormat df = new DecimalFormat(pattern);

获取格式化字符串

String formattedString = df.format(num);

并享受您自己的字符串:)

如果您需要有关如何构建模式的帮助,请参阅文档:

http://docs.oracle.com/javase/7/docs/api/java/text /DecimalFormat.html

Extract the double using getDouble:

double num = resultSet.getDouble();

Create a decimal formatter specifying the pattern you want to use. If you don't specify it, the default locale pattern is used:

DecimalFormat df = new DecimalFormat(pattern);

Obtain the formatted string

String formattedString = df.format(num);

And enjoy your own string :)

if you need help on how to build a pattern, refer to the documentation:

http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文