Skip to content

Commit

Permalink
TenThousands
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifnimah committed Jul 23, 2023
1 parent 0678a1f commit c350aa1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 25 deletions.
44 changes: 43 additions & 1 deletion NumToWords/EntryAr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ func (Entry *EntryAr) Translate(Input int) string {
{
Result = Entry.handleHundreds(Input)
}
case Input < 100000: //1000-9999
case Input < 10000: //1000-9999
{
Result = Entry.handleThousands(Input)
}
case Input < 100000: //10000-99999
{
Result = Entry.handleTenThousands(Input)
}
case Input < 1000000: //100000-999999
{
Result = Entry.handleHundredsThousands(Input)
}
case Input < 1000000000: //1000000-9999999
{
Result = Entry.handleMillions(Input)
}
}

//if Input < 10 {
Expand Down Expand Up @@ -101,6 +113,36 @@ func (EntAr EntryAr) handleThousands(Input int) string {
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

func (EntAr EntryAr) handleTenThousands(Input int) string {
And := ""
Seg01 := EntAr.LocalizedEntity.TenThousands[(Input / 10000)]
Seg03 := EntAr.Translate(Input % 10000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

func (EntAr EntryAr) handleHundredsThousands(Input int) string {
And := ""
Seg01 := EntAr.LocalizedEntity.HundredThousands[(Input / 100000)]
Seg03 := EntAr.Translate(Input % 100000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

func (EntAr EntryAr) handleMillions(Input int) string {
And := ""
Seg01 := EntAr.LocalizedEntity.Millions[(Input / 1000000)]
Seg03 := EntAr.Translate(Input % 1000000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

func (Entry EntryAr) ZeroResponse() string {
return Entry.LocalizedEntity.Zero
}
27 changes: 15 additions & 12 deletions NumToWords/locales/Lang.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package locales

type Lang struct {
Units []string
Teens []string
Tens []string
Hundreds []string
Thousands []string
And string
Zero string
Hundred string
Thousand string
Million string
Billion string
Trillion string
Units []string
Teens []string
Tens []string
Hundreds []string
Thousands []string
TenThousands []string
HundredThousands []string
Millions []string
And string
Zero string
Hundred string
Thousand string
Million string
Billion string
Trillion string
}
25 changes: 14 additions & 11 deletions NumToWords/locales/ar.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package locales

var AR = Lang{
Units: []string{"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Teens: []string{"عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"},
Tens: []string{"", "", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"},
Hundreds: []string{"", "مئة", "مئتان", "ثلاثمئة", "اربعمئة", "خمسمئة", "ستمئة", "سبعمئة", "ثمانمئة", "تسعمئة"},
Thousands: []string{"", "ألف", "ألفان", "ثلاثة آلاف", "اربعة آلاف", "خمسة آلاف", "ستة آلاف", "سبعة آلاف", "ثمانية آلاف", "تسعة آلاف"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الف",
Million: "مليون",
Billion: "مليار",
Units: []string{"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Teens: []string{"عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"},
Tens: []string{"", "", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"},
Hundreds: []string{"", "مئة", "مئتان", "ثلاثمئة", "اربعمئة", "خمسمئة", "ستمئة", "سبعمئة", "ثمانمئة", "تسعمئة"},
Thousands: []string{"", "ألف", "ألفان", "ثلاثة آلاف", "اربعة آلاف", "خمسة آلاف", "ستة آلاف", "سبعة آلاف", "ثمانية آلاف", "تسعة آلاف"},
TenThousands: []string{"", "عشرة آلاف", "عشرون الف", "ثلاثون الف", "اربعون الف", "خمسون الف", "ستون الف", "سبعون الف", "ثمانون الف", "تسعون الف"},
HundredThousands: []string{"", "مئة الف", "مئتان الف", "ثلاثمئة الف", "اربعمئة الف", "خمسمئة الف", "ستمئة الف", "سبعمئة الف", "ثمانمئة الف", "تسعمئة الف"},
Millions: []string{"", "مليون", "مليونين", "ثلاثة ملايين", "اربعة ملايين", "خمسة ملايين", "ستة ملايين", "سبعة ملايين", "ثمانية ملايين", "تسعة ملايين"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الف",
Million: "مليون",
Billion: "مليار",
}
2 changes: 1 addition & 1 deletion _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
input := 9824
input := 95001
words, err := NumToWords.Convert(input, "ar")
if err != nil {
return
Expand Down

0 comments on commit c350aa1

Please sign in to comment.