0

I tried to split real and decimal values. For eg. 209/100 => 2.09 So i want to store 2 is one variable and 0.09 into another variable. but its return zero always.

uint256 realToken = (209/100) ;                    //output 2
uint256 refundToken =   ((209/100) - realToken  )*10**18;   //output is 0

refundToken value should be 90000000000000000 but returned 0

Please give suggestion and

0

You should use the modulo operator to get the remainder of a division operation:

uint division = (209/100); // division == 2
uint modulus = (209%100);  // modulus == 9

Your corrected code would look like:

uint256 refundToken =   ((209%100)*10**18)/100;
0

You should change your second expression for right implementation as:

uint256 refundToken = ((209) - realToken*100)*10**18)/100;

It should work.

1
  • Yeah, we have to multiply first to get the division right. – Anupam Kumar Apr 13 at 9:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.