Tuesday, June 11, 2013

CRYSTAL REPORTS - SHOW NUMBERS IN WORDS - IN LAKHS & CRORES FORMAT

We can use toWords() Function in crystal reports to show numbers in words. But it does not supports South Asian numbering system (in Lakh & Crore). The following Crystal reports function helps to show amounts in Lakh & Crore.

Create a new formula field and place following script in it.

numbervar pVal:=0;
numbervar Amount:=0;
numbervar frPart:=0;
stringvar InWords :="Rupees ";

Amount := 10000000.75;    [Assign your amount here]

if Amount > 10000000 then pVal := truncate(Amount/10000000);
if Amount = 10000000 then pVal := 1;

   if pVal = 1 then
        InWords := InWords + " " + towords(pVal,0) + " crore"
   else
        if pVal > 1 then InWords := InWords + " " + towords(pVal,0) + " crores";


    Amount := Amount - pVal * 10000000;
    pVal := 0;
    if Amount > 100000 then pVal := truncate(Amount/100000);
    if Amount = 100000 then pVal := 1;
  
   
    if pVal = 1 then
        InWords := InWords + " " + towords(pVal,0) + " lakhs"
    Else
        If pVal > 1 then InWords := InWords + " " + ToWords(pVal,0) + " Lakhs";

        Amount := Amount - pVal * 100000;

        if Amount >= 1 then InWords := InWords + " " + towords(truncate(Amount),0);

        frPart := (Amount - truncate(Amount)) * 100;

        if frPart > 0 then
            InWords := InWords + " and " + towords(frPart,0) + " paisa only"
        else
            InWords := InWords + " only";

ProperCase(InWords)
     


No comments:

Post a Comment