> For the complete documentation index, see [llms.txt](https://nocode-artisan.gitbook.io/plotly-charts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nocode-artisan.gitbook.io/plotly-charts/additional-resources/formatting-cheat-sheet.md).

# Formatting Cheat Sheet

### Number Formatting

1. **Fixed Decimal Format (`f`)**:
   * **Example**: Formatting `12345.6789` to two decimal places.
   * **D3 Format**: `d3.format(".2f")`
   * **Output**: `"12345.68"`
2. **Percentage Format (`%`)**:
   * **Example**: Formatting `0.123` as a percentage.
   * **D3 Format**: `d3.format(".1%")`
   * **Output**: `"12.3%"`
3. **Scientific Notation (`e`)**:
   * **Example**: Formatting `12345` in scientific notation.
   * **D3 Format**: `d3.format(".2e")`
   * **Output**: `"1.23e+4"`
4. **SI Prefix with Significant Digits (`s`)**:
   * **Example**: Formatting `12345` with SI prefix.
   * **D3 Format**: `d3.format(".3s")`
   * **Output**: `"12.3k"`
5. **Rounded (`r`)**:
   * **Example**: Rounding `12345.6789`.
   * **D3 Format**: `d3.format(".4r")`
   * **Output**: `"12350"`
6. **Comma Separated (`,`)**:
   * **Example**: Formatting `12345.6789` with comma separation.
   * **D3 Format**: `d3.format(",.2f")`
   * **Output**: `"12,345.68"`
7. **Currency (`$`)**:
   * **Example**: Formatting `12345.67` as currency.
   * **D3 Format**: `d3.format("$,.2f")`
   * **Output**: `"$12,345.67"`
8. **Binary (`b`)**:
   * **Example**: Formatting `10` in binary.
   * **D3 Format**: `d3.format("b")`
   * **Output**: `"1010"`
9. **Hexadecimal (`x` or `X`)**:
   * **Example**: Formatting `255` in hexadecimal.
   * **D3 Format**: `d3.format("x")`
   * **Output**: `"ff"`
10. **Zero Padding (`0`)**:
    * **Example**: Formatting `5` as a two-digit number.
    * **D3 Format**: `d3.format("02d")`
    * **Output**: `"05"`

These examples show how D3.js can format numbers in many ways, including fixed decimals, percentages, scientific notation, and more. The format specifiers (like `.2f`, `.1%`, `.3s`) determine the precise formatting method.

For more detailed information and examples, you can refer to the [D3.js Format API Reference](https://github.com/d3/d3-format/blob/main/README.md).

***

### Time Formatting

1. **Abbreviated Weekday Name (`%a`)**:
   * **Example**: Formatting a date to show the abbreviated weekday.
   * **D3 Format**: `d3.timeFormat("%a")`
   * **Output for a Sunday**: `"Sun"`
2. **Full Weekday Name (`%A`)**:
   * **Example**: Formatting a date to show the full weekday name.
   * **D3 Format**: `d3.timeFormat("%A")`
   * **Output for a Sunday**: `"Sunday"`
3. **Abbreviated Month Name (`%b`)**:
   * **Example**: Formatting a date to show the abbreviated month name.
   * **D3 Format**: `d3.timeFormat("%b")`
   * **Output for January**: `"Jan"`
4. **Full Month Name (`%B`)**:
   * **Example**: Formatting a date to show the full month name.
   * **D3 Format**: `d3.timeFormat("%B")`
   * **Output for January**: `"January"`
5. **Zero-Padded Day of the Month (`%d`)**:
   * **Example**: Formatting a date to show the day of the month with zero padding.
   * **D3 Format**: `d3.timeFormat("%d")`
   * **Output for the 5th of the month**: `"05"`
6. **24-Hour Clock Hour (`%H`)**:
   * **Example**: Formatting a time to show the hour in 24-hour format.
   * **D3 Format**: `d3.timeFormat("%H")`
   * **Output for 3 PM**: `"15"`
7. **12-Hour Clock Hour (`%I`)**:
   * **Example**: Formatting a time to show the hour in 12-hour format.
   * **D3 Format**: `d3.timeFormat("%I")`
   * **Output for 15:00 (3 PM)**: `"03"`
8. **Month as Decimal Number (`%m`)**:
   * **Example**: Formatting a date to show the month as a decimal number.
   * **D3 Format**: `d3.timeFormat("%m")`
   * **Output for January**: `"01"`
9. **Minute as Decimal Number (`%M`)**:
   * **Example**: Formatting a time to show the minute.
   * **D3 Format**: `d3.timeFormat("%M")`
   * **Output for 07 minutes past**: `"07"`
10. **AM or PM (`%p`)**:
    * **Example**: Formatting a time to indicate AM or PM.
    * **D3 Format**: `d3.timeFormat("%p")`
    * **Output for 3 PM**: `"PM"`
11. **Second as Decimal Number (`%S`)**:
    * **Example**: Formatting a time to show the second.
    * **D3 Format**: `d3.timeFormat("%S")`
    * **Output for 09 seconds past**: `"09"`
12. **Year without Century (`%y`)**:
    * **Example**: Formatting a date to show the year without the century.
    * **D3 Format**: `d3.timeFormat("%y")`
    * **Output for 2024**: `"24"`
13. **Year with Century (`%Y`)**:
    * **Example**: Formatting a date to show the full year.
    * **D3 Format**: `d3.timeFormat("%Y")`
    * **Output for 2024**: `"2024"`

These examples demonstrate how to format dates and times in D3.js using different directives. By combining these directives, you can create custom formats for any date or time value. For more detailed information and examples, refer to the [D3.js Time Format API Reference](https://github.com/d3/d3-time-format/blob/main/README.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://nocode-artisan.gitbook.io/plotly-charts/additional-resources/formatting-cheat-sheet.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
