简体   繁体   English

在应用程序脚本中将数字转换为货币?

[英]Convert number to currency in apps script?

I'm wanting to convert a specific range of numbers to currency.我想将特定范围的数字转换为货币。 I'm not sure if such formatting exists in google apps script.我不确定谷歌应用脚本中是否存在这种格式。 I notice that when defining one cell value with a "$", it automatically declares any other numbers in that range with a "$".我注意到,当用“$”定义一个单元格值时,它会自动用“$”声明该范围内的任何其他数字。 So I assume that there is some kind of currency type.所以我假设有某种货币类型。

If so, is there some type of fancy method to convert a number to this currency format or am I to simply convert each number to a string and add a "$" in front of each one.如果是这样,是否有某种奇特的方法可以将数字转换为这种货币格式,或者我是否只需将每个数字转换为字符串并在每个数字前面添加一个“$”。

Any help would be appreciated, thank you.任何帮助将不胜感激,谢谢。

Google Apps Script uses JavaScript, as the later doesn't have a currency data type, Google Apps Script either. Google Apps 脚本使用 JavaScript,因为后者没有货币数据类型,Google Apps 脚本也没有。

It's worthy to note that Google Sheets stores "currency" values as numbers.值得注意的是,Google 表格将“货币”值存储为数字。 The "$" is added by the automatic number formatting feature. “$”是由自动数字格式化功能添加的。 If you want that your script adds this formatting use setNumberFormat .如果您希望脚本添加此格式,请使用setNumberFormat

Related有关的

You can use a built-in Javascript functionality like this:您可以使用内置的 Javascript 功能,如下所示:

var numberToCurrency = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'});

numberToCurrency.format(3600);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM