0

I am trying to calculate a percentage of a certain number, to do so I pass to my contract the numerator and denominator and do the following math:

amountToAdvance = (_amount * _numeratorPercentageAdvanced) / _denumeratorPercentageAdvanced;

I unfortunately keep getting and invalid opcode error on this specific line. The numbers I am trying to pass are all uint.

_amount = 10000
_numeratorPercentageAdvanced = 8
_denumeratorPercentageAdvanced = 10

UPDATED

Here is the function where the operation is located:

function loan(uint _amount, uint _fee, uint _numeratorPercentageAdvanced, uint _denumeratorPercentageAdvanced) public {         
        loanData.amountETH = _amount;         
        loanData.fee = _fee;                        

        loanState = LoanState.not_funded;         
        loanReceipiant = msg.sender;       

        amountToAdvance = (_amount * _numeratorPercentageAdvanced) / _denumeratorPercentageAdvanced;

        NewLoan(this, loanData.amountETH, loanData.fee);     
    }   

If I comment the line the code compiles fine. What am I missing ?

  • Code runs fine for me. What data types are the variables? – Linmao Song Feb 8 '18 at 15:59
  • all uints like stated in the question – Rémi Feb 8 '18 at 16:11
  • What happens prior to this line? Perhaps it's just coincidence, and you're repeatedly running out of gas on that line. Just a thought. Don't know for sure. More code would help. – Thomas Jay Rush Feb 8 '18 at 16:23
  • Its a consturctor function so called right at the creation of the loan, I updated the question above. – Rémi Feb 8 '18 at 17:05
  • I'm still not able to reproduce with the given function. I reconstructed the state variables (the struct, enum, event, etc) based on what you have in the function, but still can't get any error to occur with the input you provided. Have you run it through Remix debugger? – Adam Kipnis Feb 8 '18 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.