I'm new to Java. I'm creating small tool and I'm calculating using Bidecimal. I need to do this with bigdecimal. But I don't know how to do it?
balance= a%b;
Thanks in advance. FxMax
I'm new to Java. I'm creating small tool and I'm calculating using Bidecimal. I need to do this with bigdecimal. But I don't know how to do it?
balance= a%b;
Thanks in advance. FxMax
If you are asking for the actual operation to get a remainder of a BigDecimal, you want this:
import java.math.BigDecimal;
public static void main(String[] args){
BigDecimal a = new BigDecimal(10.05);
BigDecimal b = new BigDecimal(2.10);
BigDecimal result;
result = a.remainder(b);
System.out.printf("Here we are : %s", result);
}
You can use the remainder
method. If a
, b
, and balance
are both BigDecimals
the code would look like this:
balance = a.remainder(b);
Here you go (example):
BigDecimal bigDecimal = new BigDecimal(a);
BigDecimal remainder = bigDecimal.remainder(new BigDecimal(b));
System.out.println("remainder: " + remainder);
http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#remainder(java.math.BigDecimal)