Published
Edited
Dec 26, 2019
Fork of d3.format
1 star
Insert cell
Insert cell
d3.format(".1f")(0.1 + 0.2) // fixed decimal
Insert cell
d3.format(".0%")(0.123) // rounded percentage
Insert cell
d3.format("($.2f")(-3.5) // localized fixed-point currency
Insert cell
d3.format("+20")(42) // space-filled and signed
Insert cell
d3.format(".^20")(42) // dot-filled and centered
Insert cell
d3.format(".2s")(42e6) // SI-prefix with two significant digits
Insert cell
d3.format("#x")(48879) // prefixed lowercase hexadecimal
Insert cell
d3.format(",.2r")(4223) // grouped thousands with two significant digits
Insert cell
Insert cell
d3.format("s")(1500)
Insert cell
d3.format("~s")(1500)
Insert cell
Insert cell
d3.format(".2")(42)
Insert cell
d3.format(".2")(4.2)
Insert cell
d3.format(".1")(42)
Insert cell
d3.format(".1")(4.2)
Insert cell
Insert cell
f = d3.formatPrefix(",.0", 1e-6)
Insert cell
f(0.00042)
Insert cell
f(0.0042)
Insert cell
Insert cell
s = Object.assign(d3.formatSpecifier("f"), {precision: d3.precisionFixed(0.01)})
Insert cell
d3.format(s)(42)
Insert cell
Insert cell
new d3.FormatSpecifier({type: "s"})
Insert cell
Insert cell
d3 = require("d3-format@1")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more