igDecimal与BigInteger和BigDecimal的

igDecimal与BigInteger和BigDecimal的

本文介绍了BigDecimal与BigInteger和BigDecimal的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在辩论是使用BigDecimal和BigInteger还是仅使用BigDecimal,以使我的生活更轻松,来回转换的次数更少.就资源而言,仅使用BigDecimal有不利之处吗?

I was debating whether to use BigDecimal and BigInteger or only BigDecimal to make my life easier and less converting back and forth. Is there a downside to only using BigDecimal in regards to resources?

仅使用原始数据类型和BigInteger或仅使用BigInteger来使我的生活更轻松并且减少来回转换的方式如何?

How about using only primitive data types and BigInteger or only BigInteger to make my life easier and less converting back and forth?

推荐答案

来自: http://www.javamex .com/tutorials/math/BigDecimal_BigInteger_performance.shtml

请注意,BigDecimal本质上是BigInteger的包装,它记住小数点在哪里".

Note that a BigDecimal is essentially a wrapper around a BigInteger that "remembers where the decimal point is".

由于人类习惯于处理数字,因此与整数相比,用非整数进行手工计算时,我们可能不得不思考更多"(例如,我们可能已经学会了7倍表加快某些计算的速度,但可能不是.7倍表).但是对于计算机实现而言,操作非整数本质上没有比整数更多的精力,因此,总的来说,BigDecimal上的方法的执行与BigInteger上的类似方法相似.

Because of the way we are used to dealing with numbers, as humans, we may have to "think a bit more" when calculating with non-integers by hand compared to integers (e.g. we may have learnt the 7 times table by heart to speed up certain calculations, but probably not the .7 times table). But to a computer implementation, it is essentially no more effort to manipulate non-integers than it is integers, and so on the whole, methods on BigDecimal tend to perform similarly to analogous methods on BigInteger.

这篇关于BigDecimal与BigInteger和BigDecimal的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:54