function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amit Kr SinghAmit Kr Singh 

how to convert invoice amount in word when generating invoice pdf

Example: invoice amount =1000 then should have to print 
           (one thousands )

plz help me..
Nisar799Nisar799

Hi Amit Singh,

According to me we can achieve such a functionality through the code. Please watch the below code snippet, I am sure this will help you, modify this code according to your range currently it supports 9 digits amount or number.
 

    public void getWordFormat(){
        long num = YOUR_INVOICE_AMOUNT; // Please put your amount here 
        String numInWord = getWord(num); // You will get word format of your amount here.

    }
    private String getWord(long num){
        String word=' ';
        String [] oneToNine = new String[]{'','One ','Two ','Three ','Four ','Five ','Six ','Seven ','Eight ','Nine '};
        String [] twentyToNinety = new String[]{'','Twenty ','Thirty ','Forty ','Fifty ','Sixty ','Seventy ','Eighty ','Ninety '};
        String [] tenToNineteen = new String[]{'Ten ','Eleven  ','Twelve ','Thirteen ','Fourteen ','Fifteen ','Sixteen ','Seventeen ','Eighteen ','Nineteen '};
        if(num == 0){
            word = 'Zero ';
        }else{
            while(getLength(num) > 0){
                integer numberOfDigit = getLength(num);
                if(numberOfDigit == 9){
                    if(num/100000000 == 1) {
                        word += tenToNineteen[(integer)Math.mod((num/10000000),10)];
                    }else{
                        word += twentyToNinety[(integer)(num/100000000)-1];
                        word += oneToNine[(integer)Math.mod((num/10000000),10)];
                    }
                    word += 'Crore ';
                    num = Math.mod(num , 10000000);
                }else if(numberOfDigit == 7){
                    if(num/1000000 == 1) {
                        word += tenToNineteen[(integer)Math.mod((num/100000),10)];
                    }else{
                        word += twentyToNinety[(integer)(num/1000000)-1];
                        word += oneToNine[(integer)Math.mod((num/100000),10)];
                    }
                    word += 'Lac ';
                    num = Math.mod(num , 100000);
                }else if(numberOfDigit  == 5){
                    if(num/10000 == 1) {
                        word += tenToNineteen[(integer)Math.mod((num/1000),10)];
                    }else{
                        word += twentyToNinety[(integer)(num/10000)-1];
                        word += oneToNine[(integer)Math.mod((num/1000),10)];
                    }
                    word += 'Thousand ';
                    num = Math.mod(num,1000);
                }else if(numberOfDigit  == 3){
                    word += oneToNine[(integer)Math.mod((num/100),10)];
                    word += 'Hundred ';
                    num = Math.mod(num,100);
                }else if(numberOfDigit == 1){            
                    word += oneToNine[(integer)Math.mod(num,10)];
                    num = 0;
                }else if(numberOfDigit == 8){
                    word += oneToNine[(integer)Math.mod((num/10000000),10)];
                    word += 'Crore ';
                    num = Math.mod(num,10000000);
                }else if(numberOfDigit == 6){
                    word += oneToNine[(integer)Math.mod((num/100000),10)];
                    word += 'Lac ';
                    num = Math.mod(num , 100000);
                }else if(numberOfDigit == 4){
                    word += oneToNine[(integer)Math.mod((num/1000),10)];
                    word += 'Thousand ';
                    num = Math.mod(num ,1000);
                }else if(numberOfDigit == 2){
                    if(num/10 == 1)
                        word += tenToNineteen[(integer)Math.mod(num,10)];
                    else {
                        word += twentyToNinety[(integer) (num / 10)-1];
                        word += oneToNine[(integer)Math.mod(num,10)];
                    }
                    num = 0;
                }else{
                    num = 0;
                }
            }
        }
        return word;
    }
    // Function Returns the length of a number
    private integer getLength(long num){
        integer length = 0;
        while(num > 0){
            length++;
            num /= 10;
        }
        return length;
    }
 

Feel free to ask if you have any issue in understanding the code. :) 
Thanks 
799 Coder.