google 电子表格 API 在更新单元格值时是否对数字进行四舍五入?

Does the google spreadsheet API round off numbers when updating cell values?

所以我试图更新 google sheets spreadsheet 中的值,并且出于某种原因,当我使用 spreadsheets.values.update 方法时,我的值我正在尝试填写四舍五入。

例子

sheet = service.spreadsheets()
value = [[myfunction(), 10, 123]]
body = {'values': value}
result = sheet.values().update(spreadsheetId=SPREADSHEET_ID,
                               range=RANGE_NAME,
                               valueInputOption='RAW',
                               body=body).execute()

其中 myfunction() returns 一个整数。例如,使用的整数将是 1212650293435022848.

sheet确实更新了,但是填写的值是

[1212650293435023000, 10, 123]

而不是

[1212650293435022848, 10, 123]

这是我的代码问题还是 API 本身的问题?

注意事项

Google 电子表格目前不支持大整数。这是其数字格式的限制。

可能的解决方法

您可以使用 Apps 脚本自定义函数处理字符串格式的大整数:

由于 Apps 脚本与 JavaScript 一起工作,您可以使用 BigInt() 构造函数将字符串解析为大整数。

参考

Apps Script Custom Functions

BigInt()

BigInt 还会将 6836735342561722374 等数字修改为 6836735342561722368。

最后我做到了,因此在将整数发送到电子表格之前将整数转换为字符串。这样就没有损失,我也不必使用 BigInt()。