在Java中存储大十进制数 [英] Storing large decimal numbers in Java

查看:56
本文介绍了在Java中存储大十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以双重格式存储17774132,但是自从我得到1.7774132E7以来,似乎翻了一番.

I need to store 17774132 in a double format, but it seems that double is to small since I get 1.7774132E7.

我该如何克服这个问题?我需要某种可以用浮点数保存的原语.

How can I overcome this problem? I need some kind of primitive that can hold it with floating point.

谢谢

推荐答案

在Java中,如果要对带分数的大数进行准确的计算,则应使用java.math.BigDecimal类.对应的整数是java.math.BigInteger.

In java if you want accurate calculations for large numbers with fractions, you should use java.math.BigDecimal class. The integer counterpart is java.math.BigInteger.

我还认为double可以容纳17774132,它只是在称为"E表示法"的值中显示值,科学表示法表示数字.请参考: http://en.wikipedia.org/wiki/Scientific_notation#E_notation

Also I think double can accomodate 17774132, it's just showing the value in something called as "E Notation" which a Scientific notation to denote numbers. Refer to this : http://en.wikipedia.org/wiki/Scientific_notation#E_notation

这篇关于在Java中存储大十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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