JDBC:jtds getString() 以科学记数法返回双精度数
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 getDouble 提取双精度数:
创建一个十进制格式化程序,指定要使用的模式。如果您不指定它,则使用默认的语言环境模式:
获取格式化字符串
并享受您自己的字符串:)
如果您需要有关如何构建模式的帮助,请参阅文档:
http://docs.oracle.com/javase/7/docs/api/java/text /DecimalFormat.html
Extract the double using getDouble:
Create a decimal formatter specifying the pattern you want to use. If you don't specify it, the default locale pattern is used:
Obtain the formatted string
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