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内容请搜索靠谱客的其他文章。
发表评论 取消回复