> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/appendix/gas/classes/range/number-format.md).

# range.setNumberFormat()

{% hint style="info" %}
此指令主要是用來設定「儲存格<mark style="color:yellow;">**值的格式**</mark>」(數字、文字、日期等)，但指令名稱取得實在很糟糕。
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

```javascript
// text
range.setNumberFormat("@");

// date format
range.setNumberFormat("M/d/yy");

// Money format
range.setNumberFormat("$#,##0.00;$(#,##0.00)");
```

{% endtab %}

{% tab title="📘 手冊" %}

* [Date and Number Formats](https://developers.google.com/sheets/api/guides/formats) ⭐️⭐️

* [Format numbers in a spreadsheet](https://support.google.com/docs/answer/56470) ⭐️

* [Range](/web/appendix/gas/classes/range.md) ⟩&#x20;
  * [getNumberFormat()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getnumberformat)
  * [setNumberFormat()](https://developers.google.com/apps-script/reference/spreadsheet/range#setnumberformatnumberformat)

* common <mark style="color:yellow;">**syntax characters**</mark> for <mark style="color:purple;">**custom number format**</mark>:

<table><thead><tr><th width="243">Character</th><th>Description</th></tr></thead><tbody><tr><td>0</td><td>A digit in the number. An insignificant 0 will appear in the results.</td></tr><tr><td>#</td><td>A digit in the number. An insignificant 0 will not appear in the results.</td></tr><tr><td>?</td><td>A digit in the number. An insignificant 0 will appear as a space in the results.</td></tr><tr><td>$</td><td>Formats numbers as a dollar value.</td></tr><tr><td>.(period)</td><td>Formats numbers with a decimal point.</td></tr><tr><td>,(comma)</td><td>Formats numbers with a thousands separator.</td></tr><tr><td>/</td><td>Formats numbers as a fraction.</td></tr><tr><td>%</td><td>Formats numbers as a percent</td></tr><tr><td>E</td><td>Formats numbers as an exponent.</td></tr><tr><td>"text"</td><td>Adds text to the formula. Insert the desired text within quotations for it to appear.</td></tr><tr><td>@</td><td>Displays text entered into a cell.</td></tr><tr><td>*</td><td>Repeats the following character to fill in the remaining space in the cell.</td></tr><tr><td>_ (underscore)</td><td>Adds a space equal in width to the following character.</td></tr></tbody></table>

<br>
{% endtab %}

{% tab title="🗣 討論" %}

* [Set cell format with google apps script](https://stackoverflow.com/a/38505701/5409815) ⭐️⭐️⭐️
  {% endtab %}

{% tab title="📗 參考" %}

* Chris Black ⟩ [Cell Number Formatting with Google Apps Script](https://www.blackcj.com/blog/2015/05/18/cell-number-formatting-with-google-apps-script/) ⭐️
  {% endtab %}

{% tab title="👥 相關" %}

* [ConditionalFormatRule](/web/appendix/gas/classes/conditionalformatrule.md) - 設定條件格式。
  {% endtab %}
  {% endtabs %}
