Get the name of a number, even if it's stupidly big.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

26 строки
885 B

  1. import { GetKiloName } from '../../NumberSystem'
  2. import NAMES from './names.json'
  3. import getKiloCombiningPrefix from './base/kilo/combiningPrefix'
  4. const capitalizeFirstLetter = (word: string) => word.slice(0, 1).toUpperCase() + word.slice(1)
  5. const getLongKiloName: GetKiloName = (thousandPower) => {
  6. if (thousandPower === 0) {
  7. return ''
  8. }
  9. if (thousandPower === 1) {
  10. return capitalizeFirstLetter(NAMES.thousand)
  11. }
  12. const kilo = thousandPower
  13. const kiloHundreds = Math.floor(kilo / 2 / 100)
  14. const kiloTens = Math.floor((kilo / 2 / 10) % 10)
  15. const kiloOnes = Math.floor((kilo / 2) % 10)
  16. const kiloCombiningPrefix = getKiloCombiningPrefix(kiloHundreds, kiloTens, kiloOnes)
  17. return capitalizeFirstLetter(
  18. thousandPower % 2 === 0 ? kiloCombiningPrefix + NAMES.kiloEvenSuffix : kiloCombiningPrefix + NAMES.kiloOddSuffix,
  19. )
  20. }
  21. export default getLongKiloName