generated from Zoltu/preact-es2020-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* abbreviate huge numbers * abbreviate lengthy values * Update app/ts/library/utilities.ts Co-authored-by: KillariDev <[email protected]> * Update app/ts/library/utilities.ts Co-authored-by: KillariDev <[email protected]> * remove window debug lines * fix unused import --------- Co-authored-by: KillariDev <[email protected]>
- Loading branch information
1 parent
c603ae5
commit b3dd667
Showing
3 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { parseNumericTerm } from '../library/utilities.js' | ||
|
||
export const AbbreviatedValue = ({ floatValue }: { floatValue: number }) => { | ||
const { coefficient, exponent } = parseNumericTerm(floatValue) | ||
|
||
if (exponent < 0) { | ||
const leadingZeros = Math.abs(exponent) - 1 | ||
return <>0.<small>{'0'.repeat(leadingZeros)}</small>{coefficient}</> | ||
} | ||
|
||
const prefixes = ['', 'k', 'M', 'G'] | ||
const prefix = prefixes[Math.floor(exponent/3)] | ||
const displayValue = coefficient.toFixed(3) | ||
|
||
return <>{displayValue}{prefix}</> | ||
} |
This file contains 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
This file contains 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