概述
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 bigdecimal 除100,将BigDecimal乘以100哪种方法更好?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复