how to covert the total sum into word

0
package convert;
 
class Word{ 
 
// Strings at index 0 is not used, it is to make array  
// indexing simple  
    static String one[] = {"", "one ", "two ", "three ", "four ", 
        "five ", "six ", "seven ", "eight ", 
        "nine ", "ten ", "eleven ", "twelve ", 
        "thirteen ", "fourteen ", "fifteen ", 
        "sixteen ", "seventeen ", "eighteen ", 
        "nineteen "
    }; 
 
// Strings at index 0 and 1 are not used, they is to  
// make array indexing simple  
    static String ten[] = {"", "", "twenty ", "thirty ", "forty ", 
        "fifty ", "sixty ", "seventy ", "eighty ", 
        "ninety "
    }; 
 
// n is 1- or 2-digit number  
    static String numToWords(int n, String s) { 
        String str = ""; 
        // if n is more than 19, divide it  
        if (n > 19) { 
            str += ten[n / 10] + one[n % 10]; 
        } else { 
            str += one[n]; 
        } 
 
        // if n is non-zero  
        if (n != 0) { 
            str += s; 
        } 
 
        return str; 
    } 
 
// Function to print a given number in words  
    static String convertToWords(int n) { 
        // stores word representation of given number n  
        String out = ""; 
 
        // handles digits at ten millions and hundred  
        // millions places (if any)  
        out += numToWords((int) (n / 10000000), "crore "); 
 
        // handles digits at hundred thousands and one  
        // millions places (if any)  
        out += numToWords((int) ((n / 100000) % 100), "lakh "); 
 
        // handles digits at thousands and tens thousands  
        // places (if any)  
        out += numToWords((int) ((n / 1000) % 100), "thousand "); 
 
        // handles digit at hundreds places (if any)  
        out += numToWords((int) ((n / 100) % 10), "hundred "); 
 
        if (n > 100 && n % 100 > 0) { 
            out += "and "; 
        } 
 
        // handles digits at ones and tens places (if any)  
        out += numToWords((int) (n % 100), ""); 
 
        return out; 
    }
} 

thats the java code which is coverted into jar file and stored how do i invoke it how do i achieve this?

ummekulsum4321's picture
Joined: Jan 21 2020 - 11:05pm
Last seen: 2 months 9 hours ago

2 Answers:

1

To have a custom (java) function it is possible to use scriplets. A scriplet allows you to code a function in Java and call this function in Jaspersoft. More information on this topic can be found in: http://jasperreports.sourceforge.net/sample.reference/scriptlet/

 

mtn's picture
mtn
106
Joined: Aug 22 2017 - 4:41am
Last seen: 7 months 2 weeks ago
1

This should be a simple task for the database to do.  No need to over-engineer a scriptlet solution. 

 

Here is an example from Oracle to convert a number into a string.  Other databases have similar functionality.  If it a repeated function then maybe a db function is the way to go.

select 483 as MyNumber
     , to_char(483,'RN') as Roman_To_String
     , to_char(to_date(483,'J'), 'JSP') as Julian_To_String
     , to_char(to_date(31,'DD'), 'DDTH') as Day_To_OrdinalNum
     , to_char(to_date(31,'DD'), 'DDSP') as Spelled_Number
     , to_char(to_date(31,'DD'), 'DDSPTH') as Spelled_To_Ordinal_Num
from dual;

 

Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:000081 EndFragment:000896

MYNUMBER ROMAN_TO_STRING JULIAN_TO_STRING DAY_TO_ORDINALNUM SPELLED_NUMBER SPELLED_TO_ORDINAL_NUM
483
CDLXXXIII FOUR HUNDRED EIGHTY-THREE 31ST THIRTY-ONE THIRTY-FIRST
jgust's picture
267
Joined: Jun 10 2010 - 6:39am
Last seen: 2 days 1 hour ago
Feedback
randomness