Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifnimah committed Jul 23, 2023
2 parents 6e27c3b + 4a1fffa commit 6afb136
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
78 changes: 54 additions & 24 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 All @@ -35,14 +34,6 @@ func (Entry *EntryAr) Translate(Input int) string {
{
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)
Expand Down Expand Up @@ -85,33 +76,72 @@ 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 {
var Seg01 string
var Seg03 string
var result string
And := ""
Seg01 := EntAr.LocalizedEntity.Billions[(Input / 1000000000)]
Seg03 := EntAr.Translate(Input % 1000000000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
if Input/1000000000 > 2 {
Seg01 = EntAr.Translate(Input / 1000000000)
Seg03 = EntAr.Translate(Input % 1000000000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
result = fmt.Sprintf("%s %s %s %s", Seg01, EntAr.LocalizedEntity.Billion, And, Seg03)
} else {
Seg01 = EntAr.LocalizedEntity.Billions[(Input / 1000000000)]
Seg03 = EntAr.Translate(Input % 1000000000)
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 (Entry EntryAr) ZeroResponse() 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: "مليار",
}
4 changes: 2 additions & 2 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

func main() {
input := 1155010
words, err := NumToWords.Convert(input, "ar")
input := 1000
words, err := NumToWords.Convert(input, "en")
if err != nil {
return
}
Expand Down

0 comments on commit 6afb136

Please sign in to comment.