-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnumber.go
55 lines (51 loc) · 810 Bytes
/
number.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package parse
import (
"fmt"
"strings"
)
var singles = []string{
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth",
"Ninth",
"Tenth",
"Eleventh",
"Twelfth",
"Thirteenth",
"Fourteenth",
"Fifteenth",
"Sixteenth",
"Seventeenth",
"Eighteenth",
"Nineteenth",
}
var tens = []string{
"Twenty",
"Thirty",
"Fourty",
"Fifty",
"Sixty",
"Seventy",
"Eighty",
"Ninety",
}
// PhoneticNumber converts an integer into a human readable string
func PhoneticNumber(num int) string {
if num <= 0 {
return ""
} else if num < 20 {
return singles[num-1]
} else if num%10 == 0 {
base := strings.TrimSuffix(tens[num/10-2], "ty")
return base + "tieth"
} else if num < 100 {
return fmt.Sprintf("%s-%s", tens[num/10-2], singles[num%10-1])
} else {
return ""
}
}