Get the name of a number, even if it's stupidly big.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

26 Zeilen
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