0

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.

Rubén
  • 29,320
  • 9
  • 61
  • 145
srb633
  • 675
  • 6
  • 12
  • I have to apologize for my poor English skill. Unfortunately, I cannot understand about the difference between [the number format of the cell](https://support.google.com/docs/answer/56470?co=GENIE.Platform%3DDesktop&hl=en) and your goal of `some type of fancy method to convert a number to this currency format`. Can I ask you about the detail of your goal? – Tanaike Aug 12 '20 at 01:43
  • My bad, as Ruben described because apps script is just javascript, I should have assumed their isn't a currency format. – srb633 Aug 12 '20 at 02:11

2 Answers2

1

Google Apps Script uses JavaScript, as the later doesn't have a currency data type, Google Apps Script either.

It's worthy to note that Google Sheets stores "currency" values as numbers. The "$" is added by the automatic number formatting feature. If you want that your script adds this formatting use setNumberFormat.

Related

Rubén
  • 29,320
  • 9
  • 61
  • 145
1

You can use a built-in Javascript functionality like this:

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

numberToCurrency.format(3600);