NumToEngText(ตัวเลข)
รูปแบบการใช้สูตร : Download Add-In
Private Function Str2EngText(ByVal
Num2Str As String, Optional Multi3 As Integer = 0) As String
' พัฒนาโดยคุณสาธิตและคุณอรวีร์
'
http://forum.onecenter.com/excel/
' September 2001
Dim vStr As String, hStr As String, tStr
As String, sStr As String, txt$
Dim EngStrNumStr, EngNum2Str, EngNum3Str, EngNum4Str
EngStrNumStr = Array("", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ")
EngNum2Str = Array("", "Ten ", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety ")
EngNum3Str = Array("", "Eleven ", "Twelve ", "Thirteen ", "Forteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen ")
EngNum4Str = Array("", "Thousand ",
"Million ", "Billion ")
vStr = Format(Right(Num2Str, 3), "000")
If vStr > 0 Or Multi3 = 3 Then
txt$ = EngNum4Str(Multi3) & txt$
hStr = Left(vStr, 1) ' 100
tStr = Mid(vStr, 2, 1) ' 10
sStr = Right(vStr, 1) ' 1
If (tStr = "1" And sStr > "0") Then ' 11-19
txt$ = EngNum3Str(sStr) & txt$
Else
txt$ = EngNum2Str(tStr) & EngStrNumStr(sStr) & txt$
End If
If (hStr > "0") Then txt$ = EngStrNumStr(hStr) & "Hundred " & txt$
End If
If Len(Num2Str) > 3 Then txt$ = Str2EngText(Left(Num2Str, Len(Num2Str) - 3),
Multi3 + Multi3 * (Multi3 = 3) + 1) & " " & txt$
Str2EngText = Trim(txt$)
End Function
Function NumToEngText(ByVal StrNum As String, Optional ByVal fmt As Integer, Optional ByVal prcdigit As Integer = 2, Optional BahtStr As String = "BAHT", Optional StgStr As String = "STG.", Optional OnlyStr As String = "ONLY", Optional LessStr As String = "LESS") As String
Dim TxtB$, TxtS$
' StrNum = "" & Application.Round(StrNum, prcdigit) ' ถ้าต้องการปัดทศนิยม
If Left(StrNum, 1) <> "-" Then LessStr = "" Else StrNum = Mid(StrNum, 2):
LessStr = LessStr & " "
TxtB$ = Str2EngText(Int(StrNum))
If (fmt And 1) Then TxtB$ = LCase(TxtB$) ' fmt : bit 1 force to lower case with
only first char is capital
If TxtB$ <> Empty Then ' fmt : bit 2 Thai style text "xxxxx BAHT xxx STG."
If InStr(BahtStr, ",") Then
If Int(StrNum) > 1 Then BahtStr = Mid(BahtStr, InStr(BahtStr, ",") + 1)
Else BahtStr = Left(BahtStr, InStr(BahtStr, ",") - 1)
End If
If (fmt And 2) Then TxtB$ = TxtB$ & " " & BahtStr Else TxtB$ = BahtStr & " "
& TxtB$
End If
TxtS$ = Mid(StrNum & "00000", InStr(StrNum, ".") + 1, prcdigit)
If prcdigit > 0 And StrNum <> Int(StrNum) And TxtS$ > 0 Then
If (TxtB$ <> Empty) And (fmt And 2) = 0 Then TxtB$ = TxtB$ & " AND"
If InStr(StgStr, ",") Then
If TxtS$ > 1 Then StgStr = Mid(StgStr, InStr(StgStr, ",") + 1) Else
StgStr = Left(StgStr, InStr(StgStr, ",") - 1)
End If
TxtS$ = Str2EngText(TxtS$)
If (fmt And 1) Then TxtS$ = LCase(TxtS$)
TxtB$ = TxtB$ & " " & TxtS$ & " " & StgStr
Else
If (TxtB$ <> Empty) Then TxtB$ = TxtB$ & " " & OnlyStr
End If
TxtB$ = LessStr & TxtB$
TxtB$ = UCase(Left(TxtB$, 1)) & Mid(TxtB$, 2)
NumToEngText = Trim(TxtB$)
End Function
รูปแบบการใช้
=NumToEngText(A, B, C, D, E, F, G)
Argument B C D E F G
อาจจะไม่ใส่ก็ได้เช่น
=NumToEngText(6.25)
ได้ผลเป็น
BAHT Six AND Twenty Five STG. ซึ่งเป็นวิธีเรียกใช้ที่ง่ายที่สุด
A เป็นค่าตัวเลขที่จะให้แปลงเป็นตัวอักษร
B มีค่าใดค่าหนึ่งดังนี้ 0,1,2,3 ถ้าไม่กำหนดถือเป็น 0 โดย
B=0 จะได้ BAHT Six AND Twenty Five STG.
B=1 จะได้ BAHT six AND twenty five STG. เปลี่ยนเป็นตัวเล็ก
B=2 จะได้ Six BAHT Twenty Five STG. BAHT หลัง Six
B=3 จะได้ Six BAHT twenty five STG. เปลี่ยนเป็นตัวเล็ก BAHT หลัง Six
C
จำนวนหลักหลังจุดทศนิยมที่จะอ่าน
ถ้าไม่กำหนดถือเป็น 2 ปกติการอ่านค่าเงินก็ควรเป็น 2
แต่ถ้าอ่านค่าหน่วยอื่นๆ เช่น
เรามีค่าความยาวเป็นเมตรเก็บไว้ที่ A1=6.25 เมตร
=NumToEngText(A1,2,3,"metre","mm.")
ได้ผลเป็น
Six metre Two Hundred Fifty mm.
D
เป็นหน่วยนับของเลขหน้าจุดทศนิยม
ถ้าไม่กำหนดถือว่าเป็น BAHT
ถ้าต้องการให้จำนวนที่เป็นพหูพจน์อ่านหน่วยต่างกับเอกพจน์
ให้กำหนดคำอ่านพหูพจน์เพิ่มเติม คั่นด้วย comma เช่น BAHT,BAHTS
E
เป็นหน่วยนับของเลขหลังจุดทศนิยม
ถ้าไม่กำหนดถือว่าเป็น STG. ( สามารถกำหนดคำอ่านพหูพจน์เช่นเดียวกับ D )
=NumToEngText(A1,2,2,"Baht,Bahts","Stang,Stangs")
ได้ผลเป็น
Six Bahts Twenty Five Stangs
F
เป็นคำที่ต้องการใส่ที่ส่วนท้ายถ้าไม่มีจุดทศนิยม
ถ้าไม่กำหนดถือว่าเป็น ONLY
=NumToEngText(6,2,2,"บาท","สต.","ถ้วน")
ได้ผลเป็น
Six บาท ถ้วน
G
เป็นคำที่ต้องการให้วางข้างหน้าเมื่อตัวเลขติดลบ
ถ้าไม่กำหนดถือว่าเป็น LESS
| Full Screen | Home |
| http://www.tpa.or.th/xlsiam http://xls.i.am |
03/10/2544 |