This is the function script to write the money value in string.
First, we create f_translate function below. The function has a variable to pass called iNilai with Integer as data type. iNilai will represent the value of number that will return in word. So, the function will return a variable in string. This function will called at the main function.
1:  string aSatuan[19], str, aPuluhan[9]  
2:  integer nRatus, nPuluh  
3:    
4:  aSatuan = { "one", "two", "three", "four", "five", &  
5:        "six", "seven", "eight", "nine", "ten", &  
6:        "eleven", "twelve", "thirteen", "forteen", &  
7:        "fifteen", "sixteen", "seventeen", "eighteen", &  
8:        "nineteen" }  
9:    
10:  aPuluhan = { "ten", "twenty", "thirty", "forty", "fifty", &  
11:         "sixty", "seventy", "eighty", "ninety"}  
12:            
13:  IF nilai >= 100 THEN  
14:       nRatus = Integer(String(nilai/100))  
15:       IF nRatus = 1 THEN  
16:            str += "one hundred"  
17:       ELSE  
18:            str += aSatuan[nRatus] + " hundreds"  
19:       END IF  
20:    
21:       IF nilai > 0 THEN nilai -= nRatus * 100  
22:  END IF  
23:    
24:  IF nilai >= 20 THEN  
25:       nPuluh = Integer(String(nilai/10))  
26:       IF nRatus > 0 THEN  
27:            str += " and " + aPuluhan[nPuluh]  
28:       ELSE  
29:            str += aPuluhan[nPuluh]  
30:       END IF  
31:    
32:       nilai -= nPuluh * 10  
33:    
34:       IF nilai > 0 THEN str += " " + aSatuan[nilai]  
35:  ELSE  
36:       IF nilai > 0 THEN  
37:            IF nRatus > 0 THEN  
38:                 str += " and " + aSatuan[nilai]  
39:            ELSE  
40:                 str += aSatuan[nilai]  
41:            END IF  
42:       END IF  
43:  END IF    
44:             
45:  RETURN str  
The main function is called f_moneystr with amount as a decimal variable to pass.
1:  string str  
2:  decimal nMilyar, nJuta, nRibu  
3:    
4:  IF amount < 0 THEN RETURN ""  
5:  IF amount < 1 THEN str = "zero"  
6:    
7:  IF amount >= 1000000000000.00 THEN  
8:       nMilyar = Integer(String(amount/1000000000000.00))  
9:       str += f_Translate(nMilyar) + " trillion "  
10:       amount -= (nMilyar * 1000000000000.00)  
11:  END IF  
12:    
13:  IF amount >= 1000000000 THEN  
14:       nMilyar = Integer(String(amount/1000000000))  
15:       IF nMilyar = 1 THEN  
16:            str += "one billion "  
17:       ELSE  
18:            str += f_Translate(nMilyar) + " billion "  
19:       END IF  
20:       amount -= (nMilyar * 1000000000)  
21:  END IF  
22:    
23:  IF amount >= 1000000 THEN  
24:       nJuta = Integer(String(amount/1000000))  
25:       IF nJuta = 1 THEN  
26:            str += "one million "  
27:       ELSE  
28:            str += f_Translate(nJuta) + " millions "  
29:       END IF  
30:       amount -= (nJuta * 1000000)  
31:  END IF  
32:    
33:  IF amount >= 1000 THEN  
34:       nRibu = Integer(String(amount/1000))  
35:       IF nRibu = 1 THEN  
36:            str += "one thousand "  
37:       ELSE  
38:            str += f_Translate(nRibu) + " thousands "  
39:       END IF  
40:       amount -= (nRibu * 1000)  
41:  END IF  
42:    
43:  str += f_Translate(Integer(String(amount)))  
44:  str = RightTrim(str) + " US Dollar"  
45:  amount -= Integer(String(amount))  
46:    
47:  IF amount > 0 THEN  
48:       amount *= 100  
49:       str += " and " + f_Translate(amount) + " cent"  
50:  END IF  
51:      
52:  return str  
To use this function, just call with this statement:
1:  string sMoney  
2:    
3:  sMoney = f_moneystr(99.80)  
Note: Thanks to Mr. AGP for the script :)
No comments:
Post a Comment