I use bignumber in nodejs for cloud functions with firebase.I added BigNumber at the end thinking that it might help.
JavaScript
x
10
10
1
const BigNumber = require("bignumber.js").BigNumber;
2
let Price = new BigNumber(0);
3
let Fee = new BigNumber(0.15);
4
let FeePrice = new BigNumber(0);
5
let TotalPrice = new BigNumber(0);
6
const priceValue = json["value"];
7
Price = new BigNumber(priceValue);
8
FeePrice = Price.times(Fee).toFormat(2, 6);
9
TotalPrice = Price.minus(FeePrice);
10
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)
JavaScript
1
2
1
TotalPrice = new BigNumber(Price).minus(FeePrice);
2