Number names: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 4,598: | Line 4,598: | ||
one nonillion two hundred and sixty-seven octillion six hundred and fifty septillion six hundred sextillion two hundred and twenty-eight quintillion two hundred and twenty-nine quadrillion four hundred and one trillion four hundred and ninety-six billion seven hundred and three million two hundred and five thousand three hundred and seventy-six |
one nonillion two hundred and sixty-seven octillion six hundred and fifty septillion six hundred sextillion two hundred and twenty-eight quintillion two hundred and twenty-nine quadrillion four hundred and one trillion four hundred and ninety-six billion seven hundred and three million two hundred and five thousand three hundred and seventy-six |
||
one vigintillion vigintillion |
one vigintillion vigintillion |
||
</pre> |
|||
=={{header|R}}== |
|||
Can do zero and negatives. |
|||
<lang R> |
|||
# Number Names |
|||
ones <- c("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", |
|||
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen") |
|||
tens <- c("ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety") |
|||
mags <- c("", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion") |
|||
return_hund <- function(input_number){ |
|||
if (input_number == 0) return("") |
|||
num_text <- as.character() |
|||
input_hund <- trunc(input_number / 100) |
|||
input_ten <- trunc((input_number - input_hund * 100) / 10) |
|||
input_one <- input_number %% 10 |
|||
if (input_number > 99) num_text <- paste0(ones[trunc(input_number / 100) + 1], "-hundred") |
|||
if (input_ten < 2){ |
|||
if (input_ten == 0 & input_one == 0) return(num_text) |
|||
if (input_hund > 0) return(paste0(num_text, " ", ones[input_ten * 10 + input_one + 1])) |
|||
return(paste0(ones[input_ten * 10 + input_one + 1])) |
|||
} |
|||
ifelse(input_hund > 0, |
|||
num_text <- paste0(num_text, " ", tens[input_ten]), |
|||
num_text <- paste0(tens[input_ten]) |
|||
) |
|||
if (input_one != 0) num_text <- paste0(num_text, "-", ones[input_one + 1]) |
|||
return(num_text) |
|||
} |
|||
make_number <- function(number){ |
|||
if (number == 0) return("zero") |
|||
a <- abs(number) |
|||
num_text <- as.character() |
|||
g <- trunc(log(a, 10)) + 1 |
|||
for (i in c(seq(g, 1))){ |
|||
b <- floor(a / 1000 ^ (i - 1)) |
|||
x <- return_hund(b) |
|||
if (x != "") num_text <- paste0(num_text, return_hund(b), " ", mags[i], " ") |
|||
a <- a - b * 1000 ^ (i - 1) |
|||
} |
|||
return(ifelse(sign(number) > 0, num_text, paste("negative", num_text))) |
|||
} |
|||
my_num <- data.frame(nums = c( |
|||
0, 1, -11, 13, 99, 100, -101, 113, -120, 450, -999, 1000, 1001, 1017, 3000, 3001, |
|||
9999, 10000, 10001, 10100, 10101, 19000, 20001, 25467, 99999, 100000, 1056012, |
|||
-200000, 200001, -200012, 2012567, -5685436, 5000201, -11627389, 100067652, 456000342) |
|||
) |
|||
my_num$text <- as.character(lapply(my_num$nums, make_number)) |
|||
print(my_num, right=F) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
nums text |
|||
1 0 zero |
|||
2 1 one |
|||
3 -11 negative eleven |
|||
4 13 thirteen |
|||
5 99 ninety-nine |
|||
6 100 one-hundred |
|||
7 -101 negative one-hundred one |
|||
8 113 one-hundred thirteen |
|||
9 -120 negative one-hundred twenty |
|||
10 450 four-hundred fifty |
|||
11 -999 negative nine-hundred ninety-nine |
|||
12 1000 one thousand |
|||
13 1001 one thousand one |
|||
14 1017 one thousand seventeen |
|||
15 3000 three thousand |
|||
16 3001 three thousand one |
|||
17 9999 nine thousand nine-hundred ninety-nine |
|||
18 10000 ten thousand |
|||
19 10001 ten thousand one |
|||
20 10100 ten thousand one-hundred |
|||
21 10101 ten thousand one-hundred one |
|||
22 19000 nineteen thousand |
|||
23 20001 twenty thousand one |
|||
24 25467 twenty-five thousand four-hundred sixty-seven |
|||
25 99999 ninety-nine thousand nine-hundred ninety-nine |
|||
26 100000 one-hundred thousand |
|||
27 1056012 one million fifty-six thousand twelve |
|||
28 -200000 negative two-hundred thousand |
|||
29 200001 two-hundred thousand one |
|||
30 -200012 negative two-hundred thousand twelve |
|||
31 2012567 two million twelve thousand five-hundred sixty-seven |
|||
32 -5685436 negative five million six-hundred eighty-five thousand four-hundred thirty-six |
|||
33 5000201 five million two-hundred one |
|||
34 -11627389 negative eleven million six-hundred twenty-seven thousand three-hundred eighty-nine |
|||
35 100067652 one-hundred million sixty-seven thousand six-hundred fifty-two |
|||
36 456000342 four-hundred fifty-six million three-hundred forty-two |
|||
</pre> |
</pre> |
||