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