-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Indian conversion (and subcontinent) for currencies (#155)
* Indian currency conversion (also for the subcontinent) * updated readme * Unwanted log commented out * Fixes to comments and added info about indian language
- Loading branch information
Showing
3 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package ntw | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func init() { | ||
// register the language | ||
Languages["en-in"] = Language{ | ||
Name: "Indian English", | ||
Aliases: []string{"en", "en-in", "indian", "english"}, | ||
Flag: "🇮🇳", | ||
|
||
IntegerToWords: IntegerToEnIn, | ||
} | ||
} | ||
|
||
// IntegerToEnIn converts an integer to Indian English words | ||
func IntegerToEnIn(input int) string { | ||
var indianMegas = []string{"", "thousand", "lakh", "crore", "arab", "kharab", "neel", "padma", "shankh", "mahashankh"} | ||
var indianUnits = []string{"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} | ||
var indianTens = []string{"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"} | ||
var indianTeens = []string{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"} | ||
|
||
//log.Printf("Input: %d\n", input) | ||
words := []string{} | ||
|
||
if input < 0 { | ||
words = append(words, "minus") | ||
input *= -1 | ||
} | ||
|
||
// split integer in hybrids | ||
var hybrids []int | ||
hybrids = integerToDHybrid(input) | ||
|
||
|
||
// log.Printf("Hybrids: %v\n", hybrids) | ||
|
||
// zero is a special case | ||
if len(hybrids) == 0 { | ||
return "zero" | ||
} | ||
|
||
// iterate over hybrids | ||
for idx := len(hybrids) - 1; idx >= 0; idx-- { | ||
hybrid := hybrids[idx] | ||
//log.Printf("hybrid: %d (idx=%d)\n", hybrid, idx) | ||
|
||
// nothing todo for empty hybrid | ||
if hybrid == 0 { | ||
continue | ||
} | ||
|
||
// three-digits | ||
hundreds := hybrid / 100 % 10 | ||
tens := hybrid / 10 % 10 | ||
units := hybrid % 10 | ||
//log.Printf("Hundreds:%d, Tens:%d, Units:%d\n", hundreds, tens, units) | ||
if hundreds > 0 { | ||
words = append(words, indianUnits[hundreds], "hundred") | ||
} | ||
|
||
if tens == 0 && units == 0 { | ||
goto hybridEnd | ||
} | ||
|
||
switch tens { | ||
case 0: | ||
words = append(words, indianUnits[units]) | ||
case 1: | ||
words = append(words, indianTeens[units]) | ||
break | ||
default: | ||
if units > 0 { | ||
word := fmt.Sprintf("%s-%s", indianTens[tens], indianUnits[units]) | ||
words = append(words, word) | ||
} else { | ||
words = append(words, indianTens[tens]) | ||
} | ||
break | ||
} | ||
|
||
hybridEnd: | ||
// mega | ||
if mega := indianMegas[idx]; mega != "" { | ||
words = append(words, mega) | ||
} | ||
} | ||
|
||
//log.Printf("Words length: %d\n", len(words)) | ||
return strings.Join(words, " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters