Translate

Wednesday, May 1, 2013

Converting amount to words


if Amount <=> 0 or Amount <=> 0.0
 then
 Value = "zero"
 else
 ( Amt_string = to_str (Amount) & Parts = :str.tokenize (Amt_string, ["."]) & :lst.member (Parts, Rupee_str, 1) & format_amount (Rupee_str, Rupee) & if ?:lst.length (Parts) <=> 1 then ( Paise = "" ) else ( :lst.member (Parts, Paise_str, 2) & format_amount (Paise_str, Paise) ) & if Paise <=> "" then Value = "Rupees " ++ Rupee ++ " only" else Value = "Rupees " ++ Rupee ++ " and " ++ Paise ++ " paise only" ) ; format_amount (Amount, Res) :- Length = :str.length (Amount) & Length > 2 & ! & Group_list = [" crore " = 7, " lakh " = 5, " thousand " = 3, " hundred " = 2] & loop m:prop.get (Group_list, Prop, Num_zero) define Res = "" do ( if Res? <=> "" & Length > Num_zero then ( Part1 = :str.sub (Amount, 1, ?(Length - Num_zero)) & Len1 = :str.length (Part1) & Part2 = :str.sub (Amount, ?(Len1 + 1), ?(Length - Len1)) & format_amount (Part1, Str1) & format_amount (Part2, Str2) & if ?:str.strip (Str1, " ", [mid]) <=> "" then Res = Str2 else Res = Str1 ++ Prop ++ Str2 ) else Res = Res? ) ; format_amount (Amount, Res) :- Num = to_integer (Amount) & case Num <=> 0 then Res = "" else_if Num < 20 then :$claimref:methods.get_enum_single ($techncl:general, ones_type, Res, ?to_str (Num), _) otherwise ( :$claimref:methods.get_enum_single ($techncl:general, tens_type, Str1, ?:str.sub (Amount, 1, 1), _) & format_amount (?:str.sub (Amount, 2, 1), Str2) & Res = Str1 ++ " " ++ Str2 )

No comments:

Post a Comment