d3.format() creates a formatter that converts numeric values into strings according to a format specification. Call it with a specification, then call the returned formatter with a number. section 4.4.3
Common visualization uses include:
- Format a ratio as a rounded percentage with d3.format(".0%"). section 5.1.4
- Limit a tooltip value to three digits with d3.format(".3"). section 7.3.1
- Display large values with three significant digits and a suffix such as M by using d3-format's ".3s" specification. section 11.2.3
Formatting an arc label
Calculate the arc's percentage and pass it to the formatter when setting a text element: .text(d => d3.format(".0%")(d.percentage)). The result is a rounded number with a percent sign, suitable for a donut or arc label. section 5.1.4
Formatting a tooltip
Set a tooltip's text from the hovered datum with .text(`${d3.format(".3")(d.avg_temp_F)}°F`). Formatting keeps the displayed temperature concise while the tooltip is positioned above the pointed circle. section 7.3.1
