 |
|
ช่วยเหลือหน่อยครับ crystal report formula แปลงเงินเป็นตัวอักษร Vs2010 c# |
|
 |
|
|
 |
 |
|
ให้สองอย่างเลยแล้วกัน แล้วเอาไปแก้ไขตรง if ดูนะครับ อันนี้ต้องเขียน formula
Code
if (..ThaiBath) Then(
stringVar array D:= ["","สิบ","ร้อย","พัน","หมื่น", "แสน"];
stringVar array e:= ["หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก","เจ็ด","แปด","เก้า"];
stringVar array Mn;
stringVar array Ar1;
stringVar Arr;
numberVar F;
numberVar R;
numberVar j;
numberVar k;
numberVar u;
numberVar j2;
stringVar Bh;
numberVar F2;
numberVar j3;
numberVar u1;
numberVar m3;
stringVar Bh3;
numberVar Total := abs({Rpt_OrderInvoicingCreditMemoSp.inv_total});//!!!!อย่าลืมแก้ไขให้เป็นของตัวเอง
stringvar txtmoney :=totext(Total);
//stringvar txtmoney:="11111111111.00";//totext(Total);
Mn := "";
Bh3 := "";
stringVar sm:= replace(txtmoney,",","") ;
//stringvar sm:= txtmoney;
Ar1:=Split (sm,".");
F:= Len(Ar1[1]); // หาความยาวจำนวนที่อยู่หน้าจุดทศนิยม
If F<=6 then Arr:=Ar1[1];
If F>6 and F<=12 then Arr:=Left(Ar1[1],Len(Ar1[1])-6)+":"+Right(Ar1[1],6);
If F>12 and F<=18 then Arr:=Left(Ar1[1],Len(Ar1[1])-12)+":"+ Mid(Ar1[1], F - 12 + 1, 6)+":"+Right(Ar1[1],6);
Mn:=Split (Arr,":" );
For j2:=1 to UBound (Mn) do (
F2:= Len(Mn[j2]);
For j:= 1 To F2 do (
If Mid(Mn[j2], j, 1) = "2" And F2 + 1 - j = 8 Then e[2]:= "ยี่";
If Mid(Mn[j2], j, 1) = "1" And F2 + 1 - j = 8 Then e[1]:= "";
If Mid(Mn[j2], j, 1) = "2" And F2 + 1 - j = 2 Then e[2]:= "ยี่";
If Mid(Mn[j2], j, 1) = "1" And F2 + 1 - j = 2 Then e[1]:= "";
If Mid(Mn[j2], j, 1) = "1" And F2 + 1 - j = 1 Then e[1]:= "เอ็ด";
if Mid(Mn[j2], j, 1) = "1" and F2 + 1 - J = 1 and F2 = 1 then e[1]:= "หนึ่ง";
For R:= 1 To 9 do (
u:= Val(Mid (Mn[j2],j,1));
If u = R Then Bh:= Bh + e[R] + D[F2 + 1 - j];
);
e[2]:= "สอง";
e[1]:= "หนึ่ง";
);
If j2 <> Ubound(Mn) Then Bh:= Bh + "ล้าน";
Mn[j2]:= Bh;
Bh:= "";
);
For j3:= 1 To 2 do (
If Mid(Ar1[2], j3, 1) = "2" And j3 = 1 Then e[2]:= "ยี่";
If Mid(Ar1[2], j3, 1) = "1" And j3 = 1 Then e[1]:= "";
If Mid(Ar1[2], j3, 1) = "1" And j3 = 2 Then e[1]:= "เอ็ด";
For m3:= 1 To 9 do (
u1:=Val(Mid(Ar1[2], j3, 1));
If u1 = m3 Then Bh3:= Bh3 + e[m3] + D[3 - j3];
);
e[2]:= "สอง";
e[1]:= "เอ็ด";
);
If Mn[1]<>"" and Bh3<>"" then
Join (Mn,"")+ "บาท"+Bh3 + "สตางค์"
Else If Mn[1]<>"" and Bh3="" then
Join (Mn,"")+ "บาทถ้วน"
Else If Mn[1]="" and Bh3<>"" then
Bh3 + "สตางค์"
Else
"")
else (
numberVar Total := abs({Rpt_OrderInvoicingCreditMemoSp.inv_total});
numberVar Stang;
Stang := tonumber(Split(ToText(Total),".")[2]);
// Check number has decimal and use function ToWords in Crystal Report for change.
if stang = 0 then
if {Rpt_OrderInvoicingCreditMemoSp.inv_total} >= 0 then
(ToWords(Total,0)+ " Only.")
else
("- " & ToWords(Total,0)+ " Only.")
else
(
numberVar Total := abs({Rpt_OrderInvoicingCreditMemoSp.inv_total});//!!!อย่าลืมแก้ไขให้เป็นของตัวเอง
IF {Rpt_OrderInvoicingCreditMemoSp.inv_total} >= 0 then
(ToWords(Total,2) + ".")
else
("- " & ToWords(Total,2) + ".")
//ToWords(Truncate(Total),0)+ " and "+
//ToWords((round(Remainder(Total,1),2))+ ".")
//ToWords (round(Remainder (Total,1 ),2)*100,0)+" Satang")
)
)
)
|
 |
 |
 |
 |
Date :
2012-09-13 11:13:30 |
By :
chokbunthit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
//BahtString
//ประการตัวแปรต่างๆ ::..
Local stringVar array D:=["","สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน"];
Local stringVar array E:=["หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า"];
Local stringVar array strArrNumSplit;
Local numberVar numLength=0;
Local stringVar strTmp;
Local stringVar strResualt;
Local stringVar strRevertNumber;
Local numberVar i=0;
Local numberVar j=0;
Local numberVar k=0;
Local numberVar numIndex=0;
//แยกจำนวนเต็มกับทศนิยม::.
strArrNumSplit:=Split(Cstr( {@Currency} ,2,""),".");
numLength := Length(strArrNumSplit[1]);
strRevertNumber:=StrReverse(strArrNumSplit[1]);
//วนตัวเลขจนครบจำนวนหลัก(ตัวเลขหน้าจุด)::.
for i :=1 to numLength do (
//แปลงตัวเลขเป็นตัวหนังสือ::.
for j :=1 to 9 do (
if (Mid(strRevertNumber,i,1)=CSTR(j,0)) then (
strTmp := E[j];
if ((i=1 and Mid(strRevertNumber,i,1)="1" and numLength>1 )) or
((i=7 and Mid(strRevertNumber,i,1)="1" and numLength>7 )) then
(strTmp := "เอ็ด";);
if ((i=2 or i=8) and Mid(strRevertNumber,i,1)="1") then
(strTmp :="";);
if ((i=2 or i=8) and Mid(strRevertNumber,i,1)="2") then
(strTmp := "ยี่";);
//ใส่ค่าประจำหลัก::.
if(i>1 and i<7) then
(strTmp :=strTmp+D[i];)
else if(i=7)then
(strTmp :=strTmp+D[i]; )
else if(i>7)then
( numIndex :=(i mod 7)+ 1;
strTmp := strTmp+D[numIndex];);
//::..
strResualt := strTmp + strResualt;
exit for;
);
);//End For j
);//End For i
//วนตัวเลขจนครบจำนวนหลัก(ตัวเลขหลังจุด)::.
Local stringVar strNum;
Local stringVar num1 := Mid(strArrNumSplit[2],1,1);
Local stringVar num2 := Mid(strArrNumSplit[2],2,1);
strResualt := strResualt+"บาท";
if(num1="0" and num2="0") then
(
strResualt := strResualt+"ถ้วน";
)
else
(
for i := 1 to 2 do
(
strNum :=Mid(strArrNumSplit[2],i,1);
//แปลงตัวเลขเป็นตัวหนังสือ::.
for j:=1 to 9 do
(
if(strNum =CSTR(j,0)) then
(
strTmp :=E[j];
if(i=1 and strNum="1") then (strTmp := "";);
if(i=1 and strNum="2") then (strTmp := "ยี่";);
if(i=1) then (
strTmp := strTmp+ "สิบ";
);
if(i=2 and num1<>"0" and num2="1" ) then strTmp :="เอ็ด";
strResualt := strResualt + strTmp;
exit for;
);
);
);
strResualt := strResualt+ "สตางค์";
);
ผมยัดเข้าไปแบบนี้ครับ และมันก็ใช่ได้แล้วครับ ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2012-09-13 11:37:02 |
By :
Littlefatboyz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|