帮我想一个简单的问题,我做的程序里面有很大数字例如产量上亿以上而且小数位很多。。。

tryst 2003-10-16 04:40:24
数据库里储存了numeric数字类型我怎么把他提出来啊
我用很多方法都解决不了。GETDOUBL数据太大变成1.79E
到底怎么办
...全文
91 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
tryst 2003-10-20
  • 打赏
  • 举报
回复
我是用的他但是我想保留两位小数大家知道怎么办吗
ayayanvren 2003-10-20
  • 打赏
  • 举报
回复
贴上来串位置了。
java.math包中有两个类,BigInteger和BigDecimal,可用于具有任意长度的数字,
BigInteger实现了任意长度的整数运算;
BigDecimal实现了任意精度的浮点数运算。
用valueOf方法可以将一个普通数字转换成一个大数字
(BigInteger a=BigInteger.valueOf(100); )。
但是不能用+ - * / 运算符。必须用类中的方法(BigInteger c=a.add(b);)。
////////////BigInteger
//BigInteger add(BigInteger other)
//BigInteger subtract(BigInteger other)
//BigInteger multiply(BigInteger other)
//BigInteger divide(BigInteger other)
//BigInteger mod(BigInteger other)
//BigInteger compateTo(BigInteger other)
////////////////BigDecimal
//BigDecimal add(BigDecimal other)
//BigDecimal subtract(BigDecimal other)
//BigDecimal multiply(BigDecimal other)
//BigDecimal divide(BigDecimal other)

///////////////////////////////////////////示例
import java.math.*;
import javax.swing.*;
public class BigIntegerTest
{
public static void main(String[] args)
{
String input=JOptionPane.showInputDialog("How many numbers do you need to
draw?");
int k=Integer.parseInt(input);
input=JOptionPane.showInputDialog("How many numbers do you need to draw?");
int n=Integer.parseInt(input);
BigInteger lotteryOdds=BigInteger.valueOf(1);
for(int i=1;i<=k;i++)
lotteryOdds=lotteryOdds
.multiply(BigInteger.valueOf(n-i+1))
.divide(BigInteger.valueOf(i));
System.out.println("Your odds are 1 in "+lotteryOdds+" . Good luck!");
System.exit(0);
}
}
ayayanvren 2003-10-20
  • 打赏
  • 举报
回复
java.math包中有两个类,BigInteger和BigDecimal,可用于具有任意长度的数字,

BigInteger实现了任意长度的整数运算BigDecimal实现了任意精度的浮点数运算。
用valueOf方法可以将一个普通数字转换成一个大数字(BigInteger

a=BigInteger.valueOf(100); )。
但是不能用+ - * / 运算符。必须用类中的方法(BigInteger c=a.add(b);)。
////////////BigInteger
//BigInteger add(BigInteger other)
//BigInteger subtract(BigInteger other)
//BigInteger multiply(BigInteger other)
//BigInteger divide(BigInteger other)
//BigInteger mod(BigInteger other)
//BigInteger compateTo(BigInteger other)
////////////////BigDecimal
//BigDecimal add(BigDecimal other)
//BigDecimal subtract(BigDecimal other)
//BigDecimal multiply(BigDecimal other)
//BigDecimal divide(BigDecimal other)
///////////////////////////////////////////
import java.math.*;
import javax.swing.*;
public class BigIntegerTest
{
public static void main(String[] args)
{
String input=JOptionPane.showInputDialog("How many numbers do you need to

draw?");
int k=Integer.parseInt(input);
input=JOptionPane.showInputDialog("How many numbers do you need to draw?");
int n=Integer.parseInt(input);
BigInteger lotteryOdds=BigInteger.valueOf(1);
for(int i=1;i<=k;i++)


lotteryOdds=lotteryOdds.multiply(BigInteger.valueOf(n-i+1)).divide(BigInteger.v

alueOf(i));
System.out.println("Your odds are 1 in "+lotteryOdds+" . Good luck!");
System.exit(0);
}
}
haode 2003-10-20
  • 打赏
  • 举报
回复
可以先转换成String,然后进行处理比较方便一些
xiaohaiz 2003-10-20
  • 打赏
  • 举报
回复
回复人:tryst(刘术) ( ) 信誉:95 2003-10-20 11:27:00 得分:0
?
我是用的他但是我想保留两位小数大家知道怎么办吗


@see BigDecimal#setScale(int,int)

比如:
BigDecimal newDecimal = aDecimal.setScale(2, BigDecimal.ROUND_HALF_UP);
这样就可以保留两位小数。
snoopy_ken 2003-10-20
  • 打赏
  • 举报
回复
我和tryst (刘术) 的问题基本上一致,但用了 honkyjiang(老蒋) 的方法的时候出现如下错误,是缺少哪些东西?

500 Servlet Exception
Note: sun.tools.javac.Main has been deprecated.
/test.jsp:5: Class _jsp.DecimalFormat not found.
DecimalFormat df = new DecimalFormat("##,###,###,###,###,##0.0000000000000");
^
/test.jsp:5: Class _jsp.DecimalFormat not found.
DecimalFormat df = new DecimalFormat("##,###,###,###,###,##0.0000000000000");
^
/test.jsp:9: Variable df may not have been initialized.
String str = df.format(argdouble);
^
3 errors, 1 warning

pleonheart 2003-10-16
  • 打赏
  • 举报
回复
BigDecimal啦
flyingjm 2003-10-16
  • 打赏
  • 举报
回复
我建议用BigDecimal,可以任意长的小数。
whyxx 2003-10-16
  • 打赏
  • 举报
回复
用BigDecimal,数据库里的数字形域都推荐用BigDecimal,不会丢失精度
highreport 2003-10-16
  • 打赏
  • 举报
回复
BigDecimal
honkyjiang 2003-10-16
  • 打赏
  • 举报
回复
DecimalFormat df = new DecimalFormat("##,###,###,###,###,##0.0000000000000");
double argdouble;
String str = df.format(argdouble);
mking2008 2003-10-16
  • 打赏
  • 举报
回复
BigDecimal
wolfsquare 2003-10-16
  • 打赏
  • 举报
回复
NumberFormat也可以
wolfsquare 2003-10-16
  • 打赏
  • 举报
回复
你的问题是没有将数字格式化.
你可以使用
DecimalFormat df = new DecimalFormat("0.00000000");
df.format(double);
来解决
socoolyuanyuan 2003-10-16
  • 打赏
  • 举报
回复
我也建议用long
seven1996 2003-10-16
  • 打赏
  • 举报
回复
用long试试
qiyongjun2003 2003-10-16
  • 打赏
  • 举报
回复
BigDecimal
bluesmile979 2003-10-16
  • 打赏
  • 举报
回复
用String算了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧