I'm trying to create a post API payload from Google Script & the number field needs to be passed without decimal values. However, the app script always adds a decimal 0 (Eg. 1000.0) in the end which creates issues
var amt = '1000';
Logger.log(amt);
var options = {
"method": "post",
"payload": {
"amount": parseInt(amt),
The logger replies with 1000, but when it is used in options, it passes 1000.0
Any help would be useful..
Sample:
Apps Script
var amt = '1000';
var options = {
"method": "post",
"payload": {
"amount": amt,
}
}
Receiving end:
amt = parseInt(amt);
I had the same issue, solved it by the following
var amt = parseInt('1000').toFixed(0);
Logger.log(amt);
var options = {
"method": "post",
"payload": {
"amount": amt,
}
}
Logger.log(options)
The toFixed() allows you to fix the integer to any number of decimals you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With