Skip to content

Instantly share code, notes, and snippets.

@ningunaparte
Created October 4, 2016 08:38
Show Gist options
  • Save ningunaparte/bdb0e6be3b7f675d66b7f7320c0c8682 to your computer and use it in GitHub Desktop.
Save ningunaparte/bdb0e6be3b7f675d66b7f7320c0c8682 to your computer and use it in GitHub Desktop.
Formatting numbers with d3
//BASED ON Michael Stanaland’s Block 6106487
//http://bl.ocks.org/mstanaland/6106487
Starting number: 1500
d3.format(",") : 1,500
d3.format(".1f") : 1500.0
d3.format(",.2f") : 1,500.00
d3.format("s") : 1.5k
d3.format(".1s") : 2k
d3.format(".2s") : 1.5k
function(d) { return "$" + d3.format(",.2f")(d); } : $1,500.00
d3.format(",.2%") : 150,000.00%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment