Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

javascript - Why do i get minus function error in cloud function node js?

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

question from:https://stackoverflow.com/questions/65859571/why-do-i-get-minus-function-error-in-cloud-function-node-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...