ummekulsum4321 Posted March 9, 2020 Share Posted March 9, 2020 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; }} [/code]thats the java code which is coverted into jar file and stored how do i invoke it how do i achieve this? Link to comment Share on other sites More sharing options...
mtn Posted March 9, 2020 Share Posted March 9, 2020 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/ Link to comment Share on other sites More sharing options...
jgust Posted March 9, 2020 Share Posted March 9, 2020 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_Numfrom dual; Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:000081 EndFragment:000896MYNUMBERROMAN_TO_STRINGJULIAN_TO_STRINGDAY_TO_ORDINALNUMSPELLED_NUMBERSPELLED_TO_ORDINAL_NUM483CDLXXXIIIFOUR HUNDRED EIGHTY-THREE31STTHIRTY-ONETHIRTY-FIRST Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now