Specify type `g` decimal to exponential break point

Open
#137 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
backend

Research direction

Start by reading the number formatting documentation and the implementation of the g format type; the issue does not name specific files or tests. Check how the precision option controls the decimal-to-exponential switch, then add a way to set the requested breakpoint and test the examples in the issue. Done means values beyond the chosen decimal-place threshold use exponential notation while the shown smaller values remain decimal.

Written by the indexing model from the issue text.

Description

Is there a to specify at how many decimal places type g switches from decimal to exponential?

I'd like to format everything with more than 3 decimal places as exponential:

expect(d3.format('.3~g')(0.1)).toBe('0.1')
expect(d3.format('.3~g')(0.01)).toBe('0.01')
expect(d3.format('.3~g')(-0.001)).toBe('-0.001')
expect(d3.format('.3~g')(-0.0001)).toBe('−1e-4') // actual: −0.0001
expect(d3.format('.3~g')(-0.00001)).toBe('−1e-5') // actual: −0.00001
Dominant language
JavaScript
Stars
643
Forks
107
Avg merge
6h 25m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from d3/d3-format

All issues in d3/d3-format

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.