Home > Software engineering >  How to upload a digit with 000 in Google script
How to upload a digit with 000 in Google script

Time:01-25

I have this code:

  var userProperties = PropertiesService.getUserProperties();
  var units1 = userProperties.getProperty('name');
 
  if (units1 = null){
    var userProperties = PropertiesService.getUserProperties();
    userProperties.setProperty('name', '000');
  }
 
  var userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty('name', units1   1);
 
  var userProperties = PropertiesService.getUserProperties();
  var units = userProperties.getProperty('name');

The problem is that it does not add 000 - 0.01 - 0.02. It only adds 000 - 0.1 - 0.2.

CodePudding user response:

You can simplify your script into this one:

Script:

function myFunction() {
  var userProperties = PropertiesService.getUserProperties();
  // since getProperty always returns string, parse it into float
  // if not instantiated, assign '000'
  var units1 = parseFloat(userProperties.getProperty('name')) || '000';
  Logger.log(units1)
  // add parseFloat in case units1 is still '000'
  userProperties.setProperty('name', parseFloat(units1)   0.01)
  var units = userProperties.getProperty('name');
  Logger.log(units)
}

1st run:

1st

2nd run:

2nd

This should increment every run by 0.01.

  •  Tags:  
  • Related