im working on arabic receipts. i need to convert the numbers to arabic word. what is did is converted a number to english and then replacing the english equivalent to arabic. but the grammer is'nt correct.
please advice me how do i convert the numbers in arabic format with correct grammer.
Public Shared Function SFormatNumber(ByVal X As Double) As String
Dim Letter1, Letter2, Letter3, Letter4, Letter5, Letter6 As String
Dim c As String = Format(Math.Floor(X), "000000000000")
Dim C1 As Double = Val(Mid(c, 12, 1))
Select Case C1
Case Is = 1 : Letter1 = "واحد"
Case Is = 2 : Letter1 = "اثنان"
Case Is = 3 : Letter1 = "ثلاثة"
Case Is = 4 : Letter1 = "اربعة"
Case Is = 5 : Letter1 = "خمسة"
Case Is = 6 : Letter1 = "ستة"
Case Is = 7 : Letter1 = "سبعة"
Case Is = 8 : Letter1 = "ثمانية"
Case Is = 9 : Letter1 = "تسعة"
End Select
Dim C2 As Double = Val(Mid(c, 11, 1))
Select Case C2
Case Is = 1 : Letter2 = "عشر"
Case Is = 2 : Letter2 = "عشرون"
Case Is = 3 : Letter2 = "ثلاثون"
Case Is = 4 : Letter2 = "اربعون"
Case Is = 5 : Letter2 = "خمسون"
Case Is = 6 : Letter2 = "ستون"
Case Is = 7 : Letter2 = "سبعون"
Case Is = 8 : Letter2 = "ثمانون"
Case Is = 9 : Letter2 = "تسعون"
End Select
If Letter1 <> "" And C2 > 1 Then Letter2 = Letter1 + " و" + Letter2
If Letter2 = "" Or Letter2 Is Nothing Then
Letter2 = Letter1
End If
If C1 = 0 And C2 = 1 Then Letter2 = Letter2 + "ة"
If C1 = 1 And C2 = 1 Then Letter2 = "احدى عشر"
If C1 = 2 And C2 = 1 Then Letter2 = "اثنى عشر"
If C1 > 2 And C2 = 1 Then Letter2 = Letter1 + " " + Letter2
Dim C3 As Double = Val(Mid(c, 10, 1))
Select Case C3
Case Is = 1 : Letter3 = "مائة"
Case Is = 2 : Letter3 = "مئتان"
Case Is > 2 : Letter3 = Left(SFormatNumber(C3), Len(SFormatNumber(C3)) - 1) + "مائة"
End Select
If Letter3 <> "" And Letter2 <> "" Then Letter3 = Letter3 + " و" + Letter2
If Letter3 = "" Then Letter3 = Letter2
Dim C4 As Double = Val(Mid(c, 7, 3))
Select Case C4
Case Is = 1 : Letter4 = "الف"
Case Is = 2 : Letter4 = "الفان"
Case 3 To 10 : Letter4 = SFormatNumber(C4) + " آلاف"
Case Is > 10 : Letter4 = SFormatNumber(C4) + " الف"
End Select
If Letter4 <> "" And Letter3 <> "" Then Letter4 = Letter4 + " و" + Letter3
If Letter4 = "" Then Letter4 = Letter3
Dim C5 As Double = Val(Mid(c, 4, 3))
Select Case C5
Case Is = 1 : Letter5 = "مليون"
Case Is = 2 : Letter5 = "مليونان"
Case 3 To 10 : Letter5 = SFormatNumber(C5) + " ملايين"
Case Is > 10 : Letter5 = SFormatNumber(C5) + " مليون"
End Select
If Letter5 <> "" And Letter4 <> "" Then Letter5 = Letter5 + " و" + Letter4
If Letter5 = "" Then Letter5 = Letter4
Dim C6 As Double = Val(Mid(c, 1, 3))
Select Case C6
Case Is = 1 : Letter6 = "مليار"
Case Is = 2 : Letter6 = "ملياران"
Case Is > 2 : Letter6 = SFormatNumber(C6) + " مليار"
End Select
If Letter6 <> "" And Letter5 <> "" Then Letter6 = Letter6 + " و" + Letter5
If Letter6 = "" Then Letter6 = Letter5
SFormatNumber = Letter6
End Function
A fine is a tax for doing wrong. A tax is a fine for doing well.
__________________________________________________
Please remember to click “Mark as Answer” on the post that helps you.
Shared
Function WriteInWords(ByVal NumToConvert
As Double)
As String
Dim pUnit, pTen, pHundred, pThousand
Dim pTenThousand, pHundredThousand, pMillion, pTenMillion
Dim Unit, Ten, Hundred, Thousand, TenThousand, HundredThousand, Million, TenMillion
Dim ReturnString
'Dim Units, Tens, Teens
Dim Units()
As String = {"",
"One", "Two",
"Three", "Four",
"Five", "Six",
"Seven", "Eight",
"Nine"}
Dim Tens()
As String = {"",
"Ten", "Twenty",
"Thirty", "Forty",
"Fifty", "Sixty",
"Seventy", "Eighty",
"Ninety"}
Dim Teens() As
String = {"",
"Eleven", "Twelve",
"Thirteen", "Fourteen",
"Fifteen", "Sixteen",
"Seventeen", "Eighteen",
"Nineteen"}
pUnit =
"" : pTen =
"" : pHundred =
"" : pThousand = ""
pTenThousand =
"" : pHundredThousand =
"" : pMillion =
""
Unit = NumToConvert
Mod 10
' Digit in the Units place
Ten = (NumToConvert
Mod 100) \ 10
' Digit in the Tens place
Hundred = (NumToConvert
Mod 1000) \ 100
' Digit in the Hundreds place
Thousand = (NumToConvert
Mod 10000) \ 1000
' Digit in Thousand's Units place
TenThousand = (NumToConvert
Mod 100000) \ 10000
' Digit in the Ten Thousand's place
HundredThousand = (NumToConvert
Mod 1000000) \ 100000
' Digit in the Hundred Thousand''s place
Million = (NumToConvert
Mod 10000000) \ 1000000
' Digit in the Million's place
TenMillion = (NumToConvert
Mod 100000000) \ 10000000
' Digit in the Ten Million's place
If Unit > 0
Then
pUnit =
" " & Units(Unit)
' Get One Two Three etc.
End If
If Ten > 0
Then
pTen =
" " & Tens(Ten)
' Ten Twenty etc.
End If
If Ten = 1
And Unit > 0 Then
pUnit =
" " & Teens(Unit)
' Eleven Twelve Etc.
pTen =
""
End If
If Hundred > 0
Then
pHundred =
" " & Units(Hundred) &
" Hundred" 'One Hundred Two Hundred Etc.
End If
If Thousand > 0
Then
pThousand = " " & Units(Thousand)
End If
If TenThousand > 0
Then
pTenThousand = " " & Tens(TenThousand)
End If
If TenThousand = 1
And Thousand > 0
Then
pTenThousand =
""
pThousand = " " & Teens(Thousand)
End If
If HundredThousand > 0
Then
pHundredThousand =
" " & Units(HundredThousand) &
" Hundred"
End If
If Thousand > 0
Or TenThousand > 0 Or HundredThousand > 0
Then
pThousand = pThousand &
" Thousand"
End If
If Million > 0
Then
pMillion = " " & Units(Million)
End If
If TenMillion > 0
Then
pTenMillion = " " & Tens(TenMillion)
End If
If TenMillion = 1
And Million > 0 Then
pTenMillion =
""
pMillion = " " & Teens(Million)
End If
If TenMillion > 0
Or Million > 0 Then
Is there any implementation which is not language dependant i.e. i can convert number into English,THai,Chinese,Arabic or whatever i like by just setting the language.
Thanks,
Zeeshan Umar ~Please Mark As Answer, one or multiple posts, which helped you. So that it might be useful for others~
but for Num to words the baest way to creat it for any lang is reource files or XML files to hold languwage an acorrding to the language you pull the chosen language
A fine is a tax for doing wrong. A tax is a fine for doing well.
__________________________________________________
Please remember to click “Mark as Answer” on the post that helps you.
ferozkhan
Member
36 Points
101 Posts
Spell numbers in arabic
Jan 18, 2009 12:43 PM|LINK
hi guys,
im working on arabic receipts. i need to convert the numbers to arabic word. what is did is converted a number to english and then replacing the english equivalent to arabic. but the grammer is'nt correct.
please advice me how do i convert the numbers in arabic format with correct grammer.
any help is higly appreciated
Thanks
fairozkhan
etariq
Contributor
2823 Points
514 Posts
Re: Spell numbers in arabic
Jan 18, 2009 01:42 PM|LINK
hope this helps
Public Shared Function SFormatNumber(ByVal X As Double) As String Dim Letter1, Letter2, Letter3, Letter4, Letter5, Letter6 As String Dim c As String = Format(Math.Floor(X), "000000000000") Dim C1 As Double = Val(Mid(c, 12, 1)) Select Case C1 Case Is = 1 : Letter1 = "واحد" Case Is = 2 : Letter1 = "اثنان" Case Is = 3 : Letter1 = "ثلاثة" Case Is = 4 : Letter1 = "اربعة" Case Is = 5 : Letter1 = "خمسة" Case Is = 6 : Letter1 = "ستة" Case Is = 7 : Letter1 = "سبعة" Case Is = 8 : Letter1 = "ثمانية" Case Is = 9 : Letter1 = "تسعة" End Select Dim C2 As Double = Val(Mid(c, 11, 1)) Select Case C2 Case Is = 1 : Letter2 = "عشر" Case Is = 2 : Letter2 = "عشرون" Case Is = 3 : Letter2 = "ثلاثون" Case Is = 4 : Letter2 = "اربعون" Case Is = 5 : Letter2 = "خمسون" Case Is = 6 : Letter2 = "ستون" Case Is = 7 : Letter2 = "سبعون" Case Is = 8 : Letter2 = "ثمانون" Case Is = 9 : Letter2 = "تسعون" End Select If Letter1 <> "" And C2 > 1 Then Letter2 = Letter1 + " و" + Letter2 If Letter2 = "" Or Letter2 Is Nothing Then Letter2 = Letter1 End If If C1 = 0 And C2 = 1 Then Letter2 = Letter2 + "ة" If C1 = 1 And C2 = 1 Then Letter2 = "احدى عشر" If C1 = 2 And C2 = 1 Then Letter2 = "اثنى عشر" If C1 > 2 And C2 = 1 Then Letter2 = Letter1 + " " + Letter2 Dim C3 As Double = Val(Mid(c, 10, 1)) Select Case C3 Case Is = 1 : Letter3 = "مائة" Case Is = 2 : Letter3 = "مئتان" Case Is > 2 : Letter3 = Left(SFormatNumber(C3), Len(SFormatNumber(C3)) - 1) + "مائة" End Select If Letter3 <> "" And Letter2 <> "" Then Letter3 = Letter3 + " و" + Letter2 If Letter3 = "" Then Letter3 = Letter2 Dim C4 As Double = Val(Mid(c, 7, 3)) Select Case C4 Case Is = 1 : Letter4 = "الف" Case Is = 2 : Letter4 = "الفان" Case 3 To 10 : Letter4 = SFormatNumber(C4) + " آلاف" Case Is > 10 : Letter4 = SFormatNumber(C4) + " الف" End Select If Letter4 <> "" And Letter3 <> "" Then Letter4 = Letter4 + " و" + Letter3 If Letter4 = "" Then Letter4 = Letter3 Dim C5 As Double = Val(Mid(c, 4, 3)) Select Case C5 Case Is = 1 : Letter5 = "مليون" Case Is = 2 : Letter5 = "مليونان" Case 3 To 10 : Letter5 = SFormatNumber(C5) + " ملايين" Case Is > 10 : Letter5 = SFormatNumber(C5) + " مليون" End Select If Letter5 <> "" And Letter4 <> "" Then Letter5 = Letter5 + " و" + Letter4 If Letter5 = "" Then Letter5 = Letter4 Dim C6 As Double = Val(Mid(c, 1, 3)) Select Case C6 Case Is = 1 : Letter6 = "مليار" Case Is = 2 : Letter6 = "ملياران" Case Is > 2 : Letter6 = SFormatNumber(C6) + " مليار" End Select If Letter6 <> "" And Letter5 <> "" Then Letter6 = Letter6 + " و" + Letter5 If Letter6 = "" Then Letter6 = Letter5 SFormatNumber = Letter6 End Function__________________________________________________
Please remember to click “Mark as Answer” on the post that helps you.
ferozkhan
Member
36 Points
101 Posts
Re: Spell numbers in arabic
Jan 19, 2009 05:54 AM|LINK
Hi
can u please give me the C# equivalent of the above code.
Thanks
Nemesis116
Contributor
4667 Points
927 Posts
Re: Spell numbers in arabic
Jan 19, 2009 05:57 AM|LINK
Convert VB to C#
Visit my blog
SMAS-SMAS
Contributor
2637 Points
638 Posts
Re: Spell numbers in arabic
Jan 19, 2009 06:09 AM|LINK
E Tariq it is more than excellent. Thats really great
sirdneo
All-Star
15171 Points
2509 Posts
Re: Spell numbers in arabic
Jan 19, 2009 06:31 AM|LINK
Nice code, i always found codes to convert number into english but first time I have seen arabic version. Gr8 job man.
Zeeshan Umar
~Please Mark As Answer, one or multiple posts, which helped you. So that it might be useful for others~
SMAS-SMAS
Contributor
2637 Points
638 Posts
Re: Spell numbers in arabic
Jan 19, 2009 06:52 AM|LINK
conversion from no. to english is not problem
Public
Shared Function WriteInWords(ByVal NumToConvert As Double) As String Dim pUnit, pTen, pHundred, pThousand Dim pTenThousand, pHundredThousand, pMillion, pTenMillion Dim Unit, Ten, Hundred, Thousand, TenThousand, HundredThousand, Million, TenMillion Dim ReturnString 'Dim Units, Tens, Teens Dim Units() As String = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"} Dim Tens() As String = {"", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"} Dim Teens() As String = {"", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}pUnit =
"" : pTen = "" : pHundred = "" : pThousand = ""pTenThousand =
"" : pHundredThousand = "" : pMillion = ""Unit = NumToConvert
Mod 10 ' Digit in the Units placeTen = (NumToConvert
Mod 100) \ 10 ' Digit in the Tens placeHundred = (NumToConvert
Mod 1000) \ 100 ' Digit in the Hundreds placeThousand = (NumToConvert
Mod 10000) \ 1000 ' Digit in Thousand's Units placeTenThousand = (NumToConvert
Mod 100000) \ 10000 ' Digit in the Ten Thousand's placeHundredThousand = (NumToConvert
Mod 1000000) \ 100000 ' Digit in the Hundred Thousand''s placeMillion = (NumToConvert
Mod 10000000) \ 1000000 ' Digit in the Million's placeTenMillion = (NumToConvert
Mod 100000000) \ 10000000 ' Digit in the Ten Million's place If Unit > 0 ThenpUnit =
" " & Units(Unit) ' Get One Two Three etc. End If If Ten > 0 ThenpTen =
" " & Tens(Ten) ' Ten Twenty etc. End If If Ten = 1 And Unit > 0 ThenpUnit =
" " & Teens(Unit) ' Eleven Twelve Etc.pTen =
"" End If If Hundred > 0 ThenpHundred =
" " & Units(Hundred) & " Hundred" 'One Hundred Two Hundred Etc. End If If Thousand > 0 Then pThousand = " " & Units(Thousand) End If If TenThousand > 0 Then pTenThousand = " " & Tens(TenThousand) End If If TenThousand = 1 And Thousand > 0 ThenpTenThousand =
"" pThousand = " " & Teens(Thousand) End If If HundredThousand > 0 ThenpHundredThousand =
" " & Units(HundredThousand) & " Hundred" End If If Thousand > 0 Or TenThousand > 0 Or HundredThousand > 0 ThenpThousand = pThousand &
" Thousand" End If If Million > 0 Then pMillion = " " & Units(Million) End If If TenMillion > 0 Then pTenMillion = " " & Tens(TenMillion) End If If TenMillion = 1 And Million > 0 ThenpTenMillion =
"" pMillion = " " & Teens(Million) End If If TenMillion > 0 Or Million > 0 ThenpMillion = pMillion &
" Million" End IfReturnString = Trim(pTenMillion & pMillion & pHundredThousand & pTenThousand & _
pThousand & pHundred & pTen & pUnit)
WriteInWords = ReturnString
End Functionsirdneo
All-Star
15171 Points
2509 Posts
Re: Spell numbers in arabic
Jan 19, 2009 07:37 AM|LINK
Is there any implementation which is not language dependant i.e. i can convert number into English,THai,Chinese,Arabic or whatever i like by just setting the language.
Zeeshan Umar
~Please Mark As Answer, one or multiple posts, which helped you. So that it might be useful for others~
SMAS-SMAS
Contributor
2637 Points
638 Posts
Re: Spell numbers in arabic
Jan 19, 2009 07:45 AM|LINK
I think you can do this for some well-known languages but to do this, it is best to create a user control.
etariq
Contributor
2823 Points
514 Posts
Re: Spell numbers in arabic
Jan 19, 2009 07:51 AM|LINK
i think there is not one for Num for month am sure that there is oen bout it have a look at a code i did here http://www.codeproject.com/KB/aspnet/DynamicMonthList.aspx
but for Num to words the baest way to creat it for any lang is reource files or XML files to hold languwage an acorrding to the language you pull the chosen language
__________________________________________________
Please remember to click “Mark as Answer” on the post that helps you.