DarioN1
DarioN1

Reputation: 2552

Angular2 - Calculate discount formula not working

I'm facing a very stupid problem with Angular2/Typescript.

I want to calculate the final price from a given discount value. This is the formula:

row.priceList = row.pricePurchase + (row.pricePurchase * row.markUp / 100);

All the properties are defined as number.

If I try to run the formula and log the values, providing pricePurchase value as 1 and markUp value as 0, the result of the formula is 10 ?

How is it possible and how can I correct it ?

Thanks to support

Upvotes: 0

Views: 217

Answers (2)

DarioN1
DarioN1

Reputation: 2552

I fixed it by changing the formula in:

+row.pricePurchase + ((+row.pricePurchase * +row.markUp) / 100);

Upvotes: 1

Pranay Rana
Pranay Rana

Reputation: 176896

you can try by using Number as below

const purchase = Number(row.pricePurchase);
row.priceList =  purchase + (purchase * Number(row.markUp) / 100);

Other way is already added by you which making use of +

const purchase = +row.pricePurchase;
row.priceList =  purchase + (purchase * +row.markUp / 100);

Upvotes: 1

Related Questions