使用java将包含大十进制数的字符串转换为十进制数 [英] Converting String containing large decimal numbers to decimal number using java

查看:609
本文介绍了使用java将包含大十进制数的字符串转换为十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试转换字符串中的大十进制值,我从数据库转换为十进制。

通过解析双方法将值转换为指数...

我可以做些什么来获得确切的值。



数据库中的值:36319512.42



字符串到十进制转换给出:3.631951242E7



预期小数值:36319512.42(独立于no。是多久)



使用的方法:





String ab = rs.getString(1);

double1 = Double.parseDouble(ab);

DecimalFormat df = new DecimalFormat( 0.00);

df.setMaximumFractionDigits(2);

df.format(double1);





System.out.println(ab:+ ab);

System.out.println(double1:+ double1);

i have been trying to convert large decimal values in string, which i get from database into decimal.
the values are converted to exponents by parse double method...
can i do something to get the exact value.

value in database : 36319512.42

string to decimal conversion gives: 3.631951242E7

expected decimal value : 36319512.42 (independent of how long the no. is)

method used:


String ab= rs.getString(1);
double1 = Double.parseDouble(ab);
DecimalFormat df = new DecimalFormat("0.00");
df.setMaximumFractionDigits(2);
df.format(double1);


System.out.println("ab: "+ ab );
System.out.println("double1: "+ double1);

推荐答案

这是因为你正在抄袭原始值,而不是 df.format(double1); 返回的字符串。将代码的最后一行更改为:

That is because you are prionting the original value, not the string returned by df.format(double1);. Change the last line of your code to:
System.out.println("double1: "+ df.format(double1));


这篇关于使用java将包含大十进制数的字符串转换为十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆