Skip to content

Instantly share code, notes, and snippets.

@donaldpipowitch
Created November 13, 2020 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donaldpipowitch/14cd82bbc9be716bfc5fa828d88b8a7e to your computer and use it in GitHub Desktop.
Save donaldpipowitch/14cd82bbc9be716bfc5fa828d88b8a7e to your computer and use it in GitHub Desktop.
Nice upper bound (e.g. for charts, ticks, scales)
function getNiceUpperBound(value: number) {
const zeroCount = String(Math.round(value)).length - 1;
const factor = Math.pow(10, zeroCount);
return Math.ceil(value / factor) * factor;
}
const upperBound = getNiceUpperBound(3464634); // 4000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment