0

I have a Google spreadsheet script that pulls some data through API. The problem is that i'm pulling some data that returns a number like this: 142499.68000000

The problem is that my spreadsheet is configured to brazilian format and i'm getting some crazy results (14.249.968.000.000,00). I want to format this number like this: 142.499,68 (we use comma and not dot as US format).

I've been playing around with .setNumberFormat() but had no success.

How can I format the number like that in my script?

1 Answer 1

3

You can use JavaScript directly and in particular Intl.NumberFormat:

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('Sheet1');
  const cell = sheet.getRange("A1");
  const number = new Intl.NumberFormat('de-DE').format(142499.68000000);
  cell.setValue(number);  
}

It works for me when I change my spreadsheet locale to Brazil.

Make sure you don't have other number formatting on the cells that could affect the formatting returned by the script.

The de-DE version returns the desired result:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.