简体   繁体   English

BigDecimal赋值运算符

[英]BigDecimal assign operator

I have a problem with assigning one big decimal value to another 我将一个大的十进制值分配给另一个有问题

I am trying such as creating one temp big decimal and add 0 to another big decimal 我正在尝试例如创建一个临时大十进制并将0添加到另一个大十进制

BigDecimal temp = new BigDecimal(0);
dropStartValue =  temp.add(newCounterValue);

However, I only want simply do the operation below on big decimals: 但是,我只想简单地对大十进制执行以下操作:

dropStartValue = newCounterValue

You haven't specified the type of either dropStartValue or newCounterValue . 您尚未指定dropStartValuenewCounterValue的类型。 If they're both BigDecimals, then this should be fine: 如果它们都是BigDecimals,那么应该没问题:

dropStartValue = newCounterValue;

Note that although that's just making both variables refer to the same object, it's safe because BigDecimal itself is immutable. 请注意,尽管这只是使两个变量都引用同一个对象,但是这是安全的,因为BigDecimal本身是不可变的。

If that's not working for you, please give details of what problems you're seeing (exceptions? compile-time errors?). 如果那对您不起作用,请提供您所遇到的问题的详细信息(例外?编译时错误?)。

Assuming this is Java ans newCounterValue is an integer type or a box thereof, dropStartValue = new BigDecimal(newCounterValue); 假设这是Java,而newCounterValue是整数类型或其框,则dropStartValue = new BigDecimal(newCounterValue); should do what you want. 应该做你想做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM