How to convert number to words (iReport)

I want to convert for example, 1000 to one thousand (currency). How can i do it in Jasper?

--------------Solutions-------------

  1. See http://www.rgagnon.com/javadetails/java-0426.html
  2. Create a class based on the given implementation.
  3. Compile the class and put it in a directory where iReport can read the file.
  4. Update the CLASSPATH in iReport to point to the directory containing the class (be aware of directory relationships to package namespaces).
  5. Restart iReport.
  6. Change the text field expression to: EnglishNumberToWords.convert( $F{field_name} )

You will have to change field_name and the data type of the convert method according to your implementation details.

An alternative to Dave's response:

1) If your RDBMS supports it (like HSQLDB, for example) you can create a user-defined, user-invoked function that takes the data model representation for a field and converts it to a presentation-layer representation. For example, a database stores timestamps internally as Modified Julian Day numbers (doubles). A Java function can be written and stored with the database (SQL/JRT) to convert from a UTC double to a localized time/date string.

2) Write an SQL Query to produce a table containing the data you want in the report. The difference is that you use your user-invoked SQL/JRT function on the source column to convert it to the presentation-layer representation in the Result Table.

3) Use your SQL Query (once you have it working) as the basis for a CREATE VIEW (DDL) statement.

4) Build your report using the newly defined View as the iReport datasource.

Advantages: No customization of iReports needed. The View you create can serve as the basis for any reporting tool, not only iReports.

Disadvantages: This creates a dependency between your database and a JRE and (most likely) your RDBMS. In order to access your user-invoked function, you'll need to store the function in the database and it will need to be able to access a JRE in order to create the View. There is a SQL/JRT standard and so it is possible that your migration target RDBMS might be able to support it, but certainly this is not ever guaranteed.

Category:ireport Time:2010-12-20 Views:3
Tags: ireport

Related post

  • Convert number to base26 column string for excel. lang perl 2010-07-06

    Possible Duplicate: How to convert a column number (eg. 127) into an excel column (eg. AA) How convert number to base26 column string for excel. lang perl --------------Solutions------------- Number::Latin If it's something quick and dirty, the follo

  • Convert number to letter with php 2010-07-30

    Possible Duplicate: Converting a number (1, 2, 3) to a string (one, two, three) in PHP I'm programming an invoice script. I'm looking for a php script that convert number to letter. Exemple, the invoice show this value : 155€ The script put automatic

  • How to convert number to words in java 2010-10-12

    We currently have a crude mechanism to convert numbers to words (e.g. using a few static arrays) and based on the size of the number translating that into an english text. But we are running into issues for numbers which are huge. 10183 = Ten thousan

  • storing date as number and convert number back in to date equivalent 2010-10-13

    is there easy way to store dates as number and convert number to date equivalent in .NET 3.5 such as julian date format?. --------------Solutions------------- You can use DateTime.Ticks to convert a DateTime to a number (more specifically - a long).

  • Convert number to time 2010-10-20

    How to convert number 1.33408564814814 to time 32:01:05? --------------Solutions------------- If you actually want the result as a character string, you could use a function like this: set serveroutput on format wrapped; declare function days_to_time

  • How can I convert number of seconds since 1970 to DateTime in c++? 2011-02-02

    How can I convert number of seconds since 1970 to DateTime in c++? I am getting the time in the below format: 1296575549:573352 The left part of the colon is in seconds and the right part in micro seconds. Please help. Thanks, Syd --------------Solut

  • Convert number larger than 5 2011-10-07

    I want convert number larger than 5 become 1-5 again, ex: 6 become 1 7 become 2 8 become 3 9 become 4 so if I enter number 6-9 to my function, it will converted to above explanation. my_function(6); //will become 1 my_function(7); //will become 2 and

  • Converting number to words in SQL 2011-12-02

    Possible Duplicate: how to write number to word function in sql server Is it possible to convert a number into words in SQL Server. EG: 12.5 as Twelve point five --------------Solutions------------- AFAIK No, but you can implement such a Methode in y

  • Converting number abbreviations (5.2k, 1.7m, etc) into valid integers with JavaScript 2011-12-04

    I have a Google Doc with a column containing a variety of numbers written in "shorthand", for example: 5k for 5,000 86.62k for 86,620 4.1m for 4,100,000 1.2b for 1,200,000,000 I'd like to do some calculations with these numbers with JavaScript (loose

  • How to convert number into K thousands M million and B billion suffix in jsp 2012-03-19

    How can i convert number into K thousands M million and B billion suffix in jsp e.g 1111 as 1.111 K etc --------------Solutions------------- Adapting the answer from over here it should look something like public static String withSuffix(long count)

  • different number format in iReport and Jasper Server 2012-04-02

    i created report in iReport, where is text field with format: new DecimalFormat("#,##0.00").format($F{NUMBER}) + " €" In iReport result is 1 234,56 €, which is OK. I am in Slovakia and this is ordinary format here. In Jasper Server is result 1,234.56

  • Converting number to words 2014-03-19

    I would like to convert number with three decimals places to words. Is there a macro available? Please help to convert Bahrain Dinar currency number to words as it has three digit decimal places. Suresh AK --------------Solutions------------- O.K. He

  • how to convert number 3,500.00 format to 3500,00 format in Excel? 2014-12-10

    how to convert number 3,500.00 format to 3500,00 format in Excel? --------------Solutions------------- Ok, for now i used replace and just replaced "," with nothing and then "." with ",". You can use the regional settings in the control panel to chan

  • Is there a way to Convert Number words to Integers? Python 2009-01-29

    I need to convert 'one' into '1' 'two' into '2' and so on. Is there a way to do this a library or a class or anything? --------------Solutions------------- The majority of this code is to set up the numwords dict, which is only done on the first call

  • Convert number to binary string 2009-03-30

    Is this the best way to convert a Python number to a hex string? number = 123456789 hex(number)[2:-1].decode('hex') Sometimes it doesn't work and complains about Odd-length string when you do 1234567890. Clarification: I am going from int to hex. Als

  • .NET convert number to string representation (1 to one, 2 to two, etc-) 2009-04-27

    Is there a built in method in .NET to convert a number to the string representation of the number? For example, 1 becomes one, 2 becomes two, etc. --------------Solutions------------- I've always been a fan of the recursive method public static strin

  • MySQL - Convert Number to English Representation 2009-06-18

    Is there a particularly easy way to convert a number like "21.08" into "Twenty One and 08/100" using MySQL? I know in Oracle there was a trick you could use that involved working with Julian dates. It would get the job done in a line or so but it doe

  • Convert number in excel into string? 2009-07-23

    i'm trying to import an excel file into SQL Server but if any of the column containing number value like "12355484645" and when it's inserted into SQL Server, the value will become "1.05e+010". Beside the methods of adding "'" in front the value or f

  • Convert Number to Corresponding Excel Column 2009-08-13

    This question already has an answer here: How to convert a column number (eg. 127) into an excel column (eg. AA) 32 answers I need some help in doing a logic that would convert a numeric value to corresponding MS Excel header value. For example: 1 =

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.340 (s). 13 q(s)