Skip to content

Commit

Permalink
Fixing millions handler
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifnimah committed Jul 23, 2023
1 parent c143e4f commit 6f2ef8e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
47 changes: 36 additions & 11 deletions NumToWords/EntryAr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type EntryAr struct {

func (Entry *EntryAr) Translate(Input int) string {
Result := ""

switch {
case Input < 10: //0-9
{
Expand Down Expand Up @@ -85,23 +84,49 @@ func (EntAr EntryAr) handleHundreds(Input int) string {
}

func (EntAr EntryAr) handleThousands(Input int) string {
var Seg01 string
var Seg03 string
var result string
And := ""
Seg01 := EntAr.Translate(Input / 1000)
Seg03 := EntAr.Translate(Input % 1000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
if Input/1000 > 2 {
Seg01 = EntAr.Translate(Input / 1000)
Seg03 = EntAr.Translate(Input % 1000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
result = fmt.Sprintf("%s %s %s %s", Seg01, EntAr.LocalizedEntity.Thousand, And, Seg03)
} else {
Seg01 = EntAr.LocalizedEntity.Thousands[(Input / 1000)]
Seg03 = EntAr.Translate(Input % 1000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
result = fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}
return fmt.Sprintf("%s %s %s %s", Seg01, EntAr.LocalizedEntity.Thousand, And, Seg03)
return result
}

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

func (EntAr EntryAr) handleBillions(Input int) string {
Expand Down
2 changes: 1 addition & 1 deletion NumToWords/locales/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var AR = Lang{
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الفاً",
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 := 1155010
input := 10000000
words, err := NumToWords.Convert(input, "ar")
if err != nil {
return
Expand Down

0 comments on commit 6f2ef8e

Please sign in to comment.