Crystal Report ToWords() Function For Crore and Lac

In order to show a number in words with 'Crore' and 'Lac' you need to create a custom function in Crystal Report. I have a function and it will convert the number with two digit decimal places.
Here it is....

numbervar numberValue:=0;
numbervar roundedValue:=0;
numbervar decimalValue:=0;
stringvar inWords:="Tk. ";

numberValue :=  56080000.34;  // You have to put it the number field from database

If numberValue >= 10000000  Then
        (roundedValue := Truncate(numberValue/10000000);
        inWords := ToWords(roundedValue,0) + " Crore";
        numberValue := numberValue - (roundedValue * 10000000));

If numberValue >= 100000 Then
        (roundedValue := Truncate(numberValue/100000);
        If Len(inWords) > 0 Then
            inWords := inWords + " " + ToWords(roundedValue,0) + " Lac"
        Else
            inWords := ToWords(roundedValue,0) + " Lac";
        numberValue := numberValue - (roundedValue * 100000));      
 
If numberValue >= 1 Then
        (roundedValue := Truncate(numberValue,0);
        If Len(inWords) > 0 Then
            inWords := inWords + " " + ToWords(roundedValue,0)
        Else
            inWords := ToWords(roundedValue,0);
        decimalValue := (numberValue - roundedValue) * 100;
        If decimalValue > 0 Then
           inWords := inWords + " Point " +  ToWords(ToNumber(Left(ToText(decimalValue,'00'),1)),0)   + " " + ToWords(ToNumber(Right(ToText(decimalValue,'00'),1)),0)          
        Else
           inWords := inWords;);

If numberValue < 1 Then
        (decimalValue := (numberValue - Truncate(numberValue,0)) * 100;
        If decimalValue > 0 Then
           (If Len(inWords) > 0 Then
                inWords := inWords + " Point " +  ToWords(ToNumber(Left(ToText(decimalValue,'00'),1)),0) + " " + ToWords(ToNumber(Right(ToText(decimalValue,'00'),1)),0)          
            Else
                inWords := "Point " +  ToWords(ToNumber(Left(ToText(decimalValue,'00'),1)),0) + " " + ToWords(ToNumber(Right(ToText(decimalValue,'00'),1)),0))          
        Else
           inWords := inWords;);

 ProperCase(replace(inWords,"-"," ")) + " Only."

Comments

Popular posts from this blog

Crystal Report Font Size Problem

Generate Auto ID With Prefix