Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find symbol using BigDecimal

I'm doing my first attempts to use BigDecimal. It seems tricky.i am running into an issue and i would like to understand what is causing it.

public static String nominator(String nbrPeople)
{
    BigDecimal nom = new BigDecimal("365") ;
    BigDecimal days = new BigDecimal("365") ;
    int limit = Integer.parseInt(nbrPeople);
    for (int i = 0 ; i < limit ; i++ )
    {
        days = days.substract(i) ;
        nom = nom.multiply(days) ;
    }
    return  nbrPeople ;
}

this is part of a larger program. it is a method that should compute something like this:

365 x (365-1) x (365-2) x (365-3) etc depending on the value of nbrPeople passed in.

i would like to understand why i get the following error message:

cannot find symbol

method substract(int)

not looking for a discussion on factorials but rather on the use of BigDecimal (or BigInteger). I'm using BigDecimal because at a later stage i will need to divide, resulting in floating point.

EDIT

EDIT 2

first edit removed (code) to make the post more readable- the correct code has been posted below by a kind programmer


1 Answers

Because the method is named subtract not substract.

And the parameter has to be BigInteger too:

http://download.oracle.com/javase/6/docs/api/java/math/BigInteger.html#subtract(java.math.BigInteger)

like image 127
RoflcoptrException Avatar answered Oct 22 '25 18:10

RoflcoptrException



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!