java 如何使用java的ResultSet获取mysql浮点数的精确值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31721060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 19:02:32  来源:igfitidea点击:

How to use ResultSet of java to get precise value of float of mysql

javamysqlresultsetfloating-accuracy

提问by martinwang1985

Is it possible in Java, I use ResultSet, to get the precise value of floatof mysql?

是否有可能在Java中,我使用的ResultSet,得到的精确值floatmysql

In my database of mysql, I have some values of floatwhich are very long(for example, 123456789, more than 7 digits), I know if I use select round(float_value_column,0)I can get the precise value. But if I use ResultSet.GetFloatof java, I can get only the rounded value(123457000, just like in mysql I made select float_value_column).

在我的mysql数据库中,我有一些float很长的值(例如123456789,超过7位),我知道如果我使用select round(float_value_column,0)我可以获得精确的值。但是如果我使用ResultSet.GetFloatjava,我只能得到四舍五入的值(123457000,就像我在 mysql 中所做的一样select float_value_column)。

May I ask, if I use ResultSet.GetDouble, may I get the precise value? or may I do like ResultSet.GetFloat(round(float_value_column,0))?

请问,如果我使用ResultSet.GetDouble,我可以得到精确的值吗?或者我可以喜欢ResultSet.GetFloat(round(float_value_column,0))吗?

Thank you very much

非常感谢你

采纳答案by Kalyan Chavali

You can try the below code

你可以试试下面的代码

ResultSet rs = .....

    BigDecimal myValue = rs.getBigDecimal("Column Name");
            float myFloatValue = myValue.floatValue();

More about BigDecimal here.

更多关于BigDecimal 在这里

You can have a look at this SOW postas well.

你也可以看看这个SOW 帖子