|
|
@@ -79,11 +79,11 @@ const makeHundredsName = (hundreds: number, tens: number, ones: number, addTensD |
|
|
|
/** |
|
|
|
* Builds a name for numbers in the millions. |
|
|
|
* @param millions - Millions digit. |
|
|
|
* @param milliaCount - Number of millia- groups. |
|
|
|
* @param longestMilliaCount - Number of millia- groups. |
|
|
|
* @returns string The millions prefix. |
|
|
|
*/ |
|
|
|
const makeMillionsPrefix = (millions: number, milliaCount: GroupPlace) => { |
|
|
|
if (milliaCount > 0) { |
|
|
|
const makeMillionsPrefix = (millions: number, longestMilliaCount: GroupPlace) => { |
|
|
|
if (longestMilliaCount > 0) { |
|
|
|
return MILLIONS_PREFIXES[millions] as MillionsPrefix; |
|
|
|
} |
|
|
|
|
|
|
@@ -94,12 +94,16 @@ const makeMillionsPrefix = (millions: number, milliaCount: GroupPlace) => { |
|
|
|
* Builds a name for numbers in the decillions. |
|
|
|
* @param decillions - Decillions digit. |
|
|
|
* @param millions - Millions digit. |
|
|
|
* @param milliaCount - Number of millia- groups. |
|
|
|
* @param longestMilliaCount - Number of millia- groups. |
|
|
|
* @returns string The decillions prefix. |
|
|
|
*/ |
|
|
|
const makeDecillionsPrefix = (decillions: number, millions: number, milliaCount: GroupPlace) => { |
|
|
|
const makeDecillionsPrefix = ( |
|
|
|
decillions: number, |
|
|
|
millions: number, |
|
|
|
longestMilliaCount: GroupPlace, |
|
|
|
) => { |
|
|
|
if (decillions === 0) { |
|
|
|
return makeMillionsPrefix(millions, milliaCount); |
|
|
|
return makeMillionsPrefix(millions, longestMilliaCount); |
|
|
|
} |
|
|
|
|
|
|
|
const onesPrefix = MILLIONS_PREFIXES[millions] as MillionsPrefix; |
|
|
@@ -112,17 +116,17 @@ const makeDecillionsPrefix = (decillions: number, millions: number, milliaCount: |
|
|
|
* @param centillions - Centillions digit. |
|
|
|
* @param decillions - Decillions digit. |
|
|
|
* @param millions - Millions digit. |
|
|
|
* @param milliaCount - Number of millia- groups. |
|
|
|
* @param longestMilliaCount - Number of millia- groups. |
|
|
|
* @returns string The centillions prefix. |
|
|
|
*/ |
|
|
|
const makeCentillionsPrefix = ( |
|
|
|
centillions: number, |
|
|
|
decillions: number, |
|
|
|
millions: number, |
|
|
|
milliaCount: GroupPlace, |
|
|
|
longestMilliaCount: GroupPlace, |
|
|
|
) => { |
|
|
|
if (centillions === 0) { |
|
|
|
return makeDecillionsPrefix(decillions, millions, milliaCount); |
|
|
|
return makeDecillionsPrefix(decillions, millions, longestMilliaCount); |
|
|
|
} |
|
|
|
|
|
|
|
const onesPrefix = MILLIONS_PREFIXES[millions] as MillionsPrefix; |
|
|
@@ -177,10 +181,10 @@ const getGroupName = (place: GroupPlace, shortenMillia: boolean) => { |
|
|
|
) |
|
|
|
.map(([groupDigits, groupPlace]) => [groupDigits.padStart(3, '0'), groupPlace] as const) |
|
|
|
.filter(([groupDigits]) => groupDigits !== EMPTY_GROUP_DIGITS) |
|
|
|
.map(([groupDigits, groupPlace]) => { |
|
|
|
.map(([groupDigits, groupPlace], _index, millias) => { |
|
|
|
const [hundreds, tens, ones] = groupDigits.split('').map(Number); |
|
|
|
if (groupPlace < 1) { |
|
|
|
return makeCentillionsPrefix(hundreds, tens, ones, groupPlace); |
|
|
|
return makeCentillionsPrefix(hundreds, tens, ones, BigInt(millias.length - 1)); |
|
|
|
} |
|
|
|
|
|
|
|
const milliaSuffix = ( |
|
|
@@ -193,7 +197,7 @@ const getGroupName = (place: GroupPlace, shortenMillia: boolean) => { |
|
|
|
return milliaSuffix; |
|
|
|
} |
|
|
|
|
|
|
|
return makeCentillionsPrefix(hundreds, tens, ones, groupPlace) + milliaSuffix; |
|
|
|
return makeCentillionsPrefix(hundreds, tens, ones, BigInt(millias.length - 1)) + milliaSuffix; |
|
|
|
}) |
|
|
|
.join(''); |
|
|
|
|
|
|
|