@@ -1843,6 +1843,7 @@ const padEvery = (str: string, places = 3) => {
1843
1843
* how many decimal points that are to be displayed (Values <10 if !long, <1000 if long).
1844
1844
* only works up to 305 (308 - 3), however it only worked up to ~14 due to rounding errors regardless
1845
1845
* @param long dictates whether or not a given number displays as scientific at 1,000,000. This auto defaults to short if input >= 1e13
1846
+ * @param fractional returns html markup when the number requires (will not display nicely with .textContent)
1846
1847
*/
1847
1848
export const format = (
1848
1849
input : Decimal | number | { [ Symbol . toPrimitive ] : unknown } | null | undefined ,
@@ -1910,22 +1911,24 @@ export const format = (
1910
1911
1911
1912
// If the power is negative, then we will want to address that separately.
1912
1913
if ( power < 0 && ! isDecimal ( input ) && fractional ) {
1914
+ const num = '<span class=\'num\'>' ;
1915
+ const den = '</span><span class=\'den\'>' ;
1913
1916
if ( power <= - 15 ) {
1914
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power - 15 ) } Qa`
1917
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power - 15 ) } Qa</span> `
1915
1918
}
1916
1919
if ( power <= - 12 ) {
1917
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power - 12 ) } T`
1920
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power - 12 ) } T</span> `
1918
1921
}
1919
1922
if ( power <= - 9 ) {
1920
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power - 9 ) } B`
1923
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power - 9 ) } B</span> `
1921
1924
}
1922
1925
if ( power <= - 6 ) {
1923
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power - 6 ) } M`
1926
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power - 6 ) } M</span> `
1924
1927
}
1925
1928
if ( power <= - 3 ) {
1926
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power - 3 ) } K`
1929
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power - 3 ) } K</span> `
1927
1930
}
1928
- return `${ format ( mantissa , accuracy , long ) } / ${ Math . pow ( 10 , - power ) } `
1931
+ return `${ num + format ( mantissa , accuracy , long ) } ${ den + Math . pow ( 10 , - power ) } </span> `
1929
1932
} else if ( power < 6 || ( long && power < 13 ) ) {
1930
1933
// If the power is less than 6 or format long and less than 13 use standard formatting (123,456,789)
1931
1934
// Gets the standard representation of the number, safe as power is guaranteed to be > -12 and < 13
0 commit comments