I use bignumber in nodejs for cloud functions with firebase.I added BigNumber at the end thinking that it might help.
const BigNumber = require("bignumber.js").BigNumber; let Price = new BigNumber(0); let Fee = new BigNumber(0.15); let FeePrice = new BigNumber(0); let TotalPrice = new BigNumber(0); const priceValue = json["value"]; Price = new BigNumber(priceValue); FeePrice = Price.times(Fee).toFormat(2, 6); TotalPrice = Price.minus(FeePrice);
I get this error in Cloud Function Log TypeError:
Price.minus is not a function
Advertisement
Answer
Your typeof Price
might be a string. So it needs to be converted to BigNumber
.
You can use TotalPrice
with BigNumber static method itself. (thanks to your comment replies)
TotalPrice = new BigNumber(Price).minus(FeePrice);