Home > Blockchain >  c# wrong number when calculating percentage
c# wrong number when calculating percentage

Time:02-11

trying to calculate and subtract the price of something, but keeps coming up wrong, and adds an extra 500m to it and cannot understand why.

here is my code

        var discountPercentage = 50 / 100;
        discountedPrice= (decimal)(discountPercentage * 150000M   10000M    0);

the answer keeps giving me 85000.0M where it should be 80000, which is half of the combined amount (150000M 10000M)

CodePudding user response:

I think your parenthesis are placed wrong in discountPercentage. It has to do with priority of operations.

discountPercentage * (150000M   10000M    0);
  • Related