我是靠谱客的博主 文艺大船,这篇文章主要介绍java bigdecimal 除100,将BigDecimal乘以100哪种方法更好?,现在分享给大家,希望可以做个参考。

Here I have a question when using Java BigDecimal.

Which way will be better when I want to multiply 100 for a object of BigDecimal.

multiply 10 twice;

movePointRight(2);

scaleByPowerOfTen(2);

any other way? please show me if there is.

BTW, it will be used for commercial calculation, so I'm considering the precision rather than the speed.

解决方案

Option 3 is the fastest. Options 1 and 2 are roughly the same (option one being to multiply by ten twice). Multiplying by 100 instead gets up near the speed of option 3.

Here's my test code:

import java.math.BigDecimal;

public class TestingStuff {

public static void main(String[] args){

BigDecimal d2 = new BigDecimal(0); // to load the big decimal class outside the loop

long start = System.currentTimeMillis();

最后

以上就是文艺大船最近收集整理的关于java bigdecimal 除100,将BigDecimal乘以100哪种方法更好?的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部