Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 谷歌脚本,操纵数值_Google Sheets_Google Apps Script - Fatal编程技术网

Google sheets 谷歌脚本,操纵数值

Google sheets 谷歌脚本,操纵数值,google-sheets,google-apps-script,Google Sheets,Google Apps Script,我在一个spreedsheet后面有一个脚本,我正在尝试将一些单元格值导出到文档中,然后通过电子邮件发送临时文档的pdv版本…(稍后将其丢弃)。我对获取的值或从spreedsheet到doc获取值的方式有问题。。我不能操纵小数点 // fix the price currency display and alignment in GOOGLE DOCUMENT TABLE! for (var i = 0; i < price.getNumRows(); i++){ for

我在一个spreedsheet后面有一个脚本,我正在尝试将一些单元格值导出到文档中,然后通过电子邮件发送临时文档的pdv版本…(稍后将其丢弃)。我对获取的值或从spreedsheet到doc获取值的方式有问题。。我不能操纵小数点

  // fix the price currency display and alignment in GOOGLE DOCUMENT TABLE!
  for (var i = 0; i < price.getNumRows(); i++){
    for (var j = 0; j < price.getRow(i).getNumCells(); j++){
      var temp = price.getCell(i, j);
      temp.getChild(0).asParagraph().setSpacingAfter(0);
      if((j == 6 || j == 7) && !temp.getText() == "" ) {
        (i > 0) ? temp.replaceText(temp.getText(), temp.getText() + " kn") : void false; // skip the first line with header titles... 
        temp.getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
      }
    }
  }
//修复GOOGLE文档表中的价格货币显示和对齐!
对于(var i=0;i0)?temp.replaceText(temp.getText(),temp.getText()+“kn”):void false;//跳过带有标题的第一行。。。
temp.getChild(0.aspagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
}
}
(i>0)之后是temp.getText()值。。有时候是这样的:55987654,我想把它四舍五入到两位数。。但不能:(


谢谢你的帮助!

我找到了解决办法

这很简单,但确实花了我一些时间。希望这能帮助其他类似情况的人

parseFloat(temp.getText()).toFixed(2) + " kn")

这就成功了,输出结果是:55,99 kn!

我找到了解决方案

这很简单,但确实花了我一些时间。希望这能帮助其他类似情况的人

parseFloat(temp.getText()).toFixed(2) + " kn")
这样做的技巧和输出是像:55,99千牛