0

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

FxMax
  • 472
  • 1
  • 5
  • 9

3 Answers3

2

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);

    }
Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
0

You can use the remainder method. If a, b, and balance are both BigDecimals the code would look like this:

balance = a.remainder(b);
pablochan
  • 5,625
  • 27
  • 42
0

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)

swinkler
  • 1,703
  • 10
  • 20