Created
November 13, 2020 07:05
-
-
Save donaldpipowitch/14cd82bbc9be716bfc5fa828d88b8a7e to your computer and use it in GitHub Desktop.
Nice upper bound (e.g. for charts, ticks, scales)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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