Formatted output (floats)

Hi everyone,
I spent so much time already looking for some classes or functions that I can use to display decimal numbers formatted with a specified width and number of significant figures, but I can't seem to find anything that works fine in Java 1.4
Does anyone know if there is something similar to printf(), but for Java?
I need to display number in the following format:
1.23
23.45 3.455
0.34 65.67 4.556
3.455 5.66 5.67 5.666
I need to have them aligned in columns.
Thanks for the help in advance.

1) Add a roundoff value exactly half of the last digit you'll retain - .005 if you are rounding to two places.
2)Convet to text: String s = "" + myFloat;
3)Find the decimal point: int decLoc = s.indexOf(".");
4)Truncate to the desired # of places: s = s.substring( 0, decLoc+2 );
5)Add enough spaces on the right to pad to the column width.
6)Use a monospaced font when you output.

Similar Messages

  • Initial-page-number not working in RTF format output

    A report has a parameter for the page number to start with. In rtf template below code is present
    <?initial-page-number:xdoxslt:ifelse(P_FIRST_PAGE_NUM!=’’,number(P_FIRST_PAGE_NUM),1)?>
    The report page number starts with the value which we pass in p_first_page_num in PDF format but in rtf format output it always starts with 1.
    Is initial-page-number not supported in RTF format output ? If not then what is the alternative?

    the method u followed is fine as need a page number staring from a specify value which u input.
    @section is only for resetting page number to 1 for every group and for that pdf and ppt will be fine but only for rtf u need to use that ( pressing F9).
    u can use @section and initial page number combined but they give u same output as get now. rtf output wont support it will only reset 1 every time
    What ever u do rtf output wont support initial page number code ..........
    i mentioned that F9 work around to mention that it is the only work around u have upto now to control rtf output with regards to page number.
    Guru's correct me if i am wrong. wait for a day or two if some one from guru's confirm it .
    If u need real confirmation raise an SR oracle will let u know .

  • 1.4.2 - What is the correct way to format output in the java.io.PrintStream

    With Java 1.4.2:
    What is the correct way to format output in the java.io.PrintStream?
    The following is incorrect, even though it is still used in the The JavaTM Tutorial at: http://java.sun.com/docs/books/tutorial/essential/
    System.out.formatThis returns "cannot resolve the method 'format'"
    Any detailed suggestions or information is greatly appreciated.

    The following is incorrect, even though it is still
    used in the The JavaTM Tutorial at:
    http://java.sun.com/docs/books/tutorial/essential/
    The whole format thing has been introduced in 1.5. The tutorial also states it's been "updated to 1.5.".
    That's all I've got to say for I don't know how you can format a PrintWriter, let alone a PrintStream, prior to 1.5. I'm not really sure there is any way. Any "legacy way", that is. There almost certainly are third-party API which achieve similar results.

  • List format output to excel sheet

    Hi,
        I have a report output in list format. I need to download that into excel sheet. Is it possible to download a list format output to excel sheet or shall I need to convert that into grid format?
    Thanks Barnita.

    HI,
    Use Menu path
    List->Save/Send->File path

  • Formatting a float in Java, help please!

    Im trying to format a float in a JTable thats been taken from an SQL database, heres what ive got:
    float price = results.getFloat(5);
    row = new Vector();
    row.addElement(new String(results.getString(1)));
    row.addElement(results.getString(2));
    row.addElement(results.getInt(3));
    row.addElement(results.getInt(4));
    row.addElement("�"+ (price));
    rows.addElement(row);
    so i've given the getFloat(5) a variable name 'price' - how do i format the float 'price' to two decimal places, like 0.00? is it some thing like:
    float price.%2f = results.getFloat(5);
    I cant remember, thanks!

    yeh i tried to implement it, but no joy, the JTable still displays to 1 decimal place, which is very odd...
    the JTable displays as strings, but its retrieving a float (results.getFloat(5)) so i thought if i called the results.getFloat as a string, then used:
    Float price = Float.valueOf(results.getFloat(5)).floatValue();
    String.format("%.2f", price);
    it would work... i was wrong, lol

  • SQL Developer formatted output

    Hello,
    Could you please help me in getting the formatted output on Oracle sql developer tool, I am not able to find andy options to set
    I have copy paste the result from this tool to excel, I am getting plain text out put, I have more columns and readablity is not there
    Regards,
    Neil
    Edited by: NeilCSE on Apr 6, 2010 6:01 AM

    Hi,
    try this.
    I am on windows
    SQL> spool c:\emp_text.txt;
    Started spooling to c:\emp_text.txt
    SQL> select ename||'|'||empno from emp;
    ENAME||'|'||EMPNO
    JAMES|7900
    FORD|7902
    MILLER|7934
    SMITH|7369
    ALLEN|7499
    WARD|7521
    JONES|7566
    MARTIN|7654
    BLAKE|7698
    CLARK|7782
    SCOTT|7788
    KING|7839
    TURNER|7844
    ADAMS|7876
    14 rows selected
    SQL> spool off;
    Stopped spooling to c:\emp_text.txtThen open in excel as delimeted by |
    Regards,
    Bhushan

  • How to get XML format output from Hyperion Financial Reporting

    Dears,
    We are using Hyperion Financial Reporting to replace FSG in fusion. I found that Hyperion FR report can be exported to html/excel/pdf format. However, I would like the report to export to xml format.It means I only need the xml data source.
    Anyone who knows how to get the xml format output from Hyperion FR, is there any avaiable API?

    I think if you export the report, you will be able to open the .des file in Notepad/Wordpad and see xml content.

  • Properly formatting output to XML

    While the code below would work to format something simple like this:
    <USERS>
    ��<USER>Tim Smith</USER>
    ��<USER>Jack Dempsey</USER>
    ��<USER>John Doe</USER>
    </USERS>
    hd.startDocument();
    AttributesImpl atts = new AttributesImpl();
    // USERS tag.
    hd.startElement("","","USERS",atts);
    for (int i=0;i<id.length;i++)
      atts.clear();
      hd.startElement("","","USER",atts);
      hd.characters(desc.toCharArray(),0,desc[i].length());
    hd.endElement("","","USER");
    hd.endElement("","","USERS");
    hd.endDocument();
    How does one do more complex nesting of xml elements? Such as if I wanted the output to resemble:
    <USERS>
    ��<USER>Tim Smith</USER>
    ��<ADDRESS>14 Main St</ADDRESS>
    ��<CITY>Denver</CITY>
    ��<STATE>CO</STATE>
    </USERS>
    Message was edited by:
    drakester
    Message was edited by:
    drakester

    I don't quit understand your answer. Serializing objects pertains to formatting output?

  • I am not able to open the html format outputs of SQR

    when I am trying to open SQR html formate output generated by SQR jobs not able to open the html format outputs of SQR getting below error
    but I am able to open pdf and excel formats outputs
    "An error was encountered while attempting to retrieve audit_control_info_frm.htm from the Hyperion Reporting and Analysis - System 9. This error is normally encountered when there is no free disk space on the machine hosting Hyperion Reporting and Analysis - System 9 Application. Hyperion Reporting and Analysis - System 9 Application uses a directory on the hard disk to store temporary files while downloading objects. To rectify this problem, if the disk hosting the Hyperion Reporting and Analysis - System 9 Application temporary directory is nearly full, free up additional disk space. After confirming that there is available disk space, restart ALL Hyperion Reporting and Analysis - System 9 servers. <p>Another possible cause of this error is that you have attempted to embed a "Versioned Collection" into your Personal Page. A "Versioned Collection" is typically created when you publish a document and request the creation of an additional compressed copy. Embedded "Versioned Collections" are not supported by Hyperion Reporting and Analysis - System 9.
    A general error was encountered contacting the server.
    Recommended Action: Contact your corporate technical support."

    Welcome to the Apple community.
    Have you tried restarting your web browser, if that doesn't help you might try emptying your web browser's cache.

  • HTML formatted output

    Hi All,
    I have xml source as,
    < SAMPLE_JOB>
    < ORG_DESCRIPTION>>& lt;UL& gt;& lt;LI& gt;& lt;DIV class=MsoNormal style=& quot;MARGIN: 0in 0in 0pt 0.25in& quot;
    & gt;& lt;SPAN style=& quot;FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt& quot;
    & gt;Design and deliver technical training courses to field service engineers, dealer, and customer support
    personnel.& lt;/SPAN& gt;& lt;/DIV& gt;& lt;/LI& gt;& lt;/UL& gt;
    < /ORG_DESCRIPTION>
    < /SAMPLE_JOB>
    when i am previewing in pdf output, i am getting the following for < ORG_DESCRIPTION>
    < UL>< LI>< DIV class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in">< SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial;
    mso-bidi-font-size: 12.0pt">Design and deliver technical training courses to field service engineers, dealer, and customer support personnel.< /SPAN>< /DIV>< /
    LI>< /UL>
    I want html formatted output. I saw tims blog. But here in my xml source i am not getting direct tags (instead of "< UL>", i am getting xml output as "& lt; UL & gt;"),
    can i also get the xsl equivalent code for tags like UL, LI, DIV, SPAN..
    Please help me.

    Your XML source is sorta odd.
    Where is it coming from?
    Word?
    This is what your xml should look like:
    < SAMPLE_JOB>
    < ORG_DESCRIPTION>Design and deliver technical training courses to field service engineers, dealer, and customer support
    personnel.< /ORG_DESCRIPTION>
    < /SAMPLE_JOB>
    Then you put it in your rtf and preview in pdf and it would look ok.
    The source xml is the problem - all this stuff is wrong or does not belong:
    & lt;/SPAN& gt;& lt;/DIV& gt;& lt;/LI& gt;& lt;/UL& gt;

  • Formatting output to a file? 1.4.2

    I am writing an application that writes result sets from an oracle 10g database query. This output combines both text and numeric.
    I cannot figure out how to justify the output to the right or left or force the fields to use a set amount of space regardless of the width of the text.
    As a result I get an outfile with perfectly lined up columns except for the one or two where instead of a four digit number there is a single number. This change in width shifts all of the output over.
    My customer goes nuts over this, surely there is a way to format output?

    OK, I tried today, I really did, I just can't get my brain around how to do what I need to accomplish so here is a pseudo example and i am hoping someone can shed some light.
    My application is abstract to enable easy addition of instances of automated reports.
    I have a 2d array that contains the column names for a given query. [0] = column name, [1] = space to be applied after results are added to a string buffer.
    So, something like this:
    StringBuffer entireQueryResults = new StringBuffer();
    String[][] QueryColumns = someObject.getQueryColumnNames();
    ResultSet currResults = someObject.getResultset();
    while(currResults.next()){
    String currRow = "";
    for(int i = 0; i < QueryColumns.length; i++){
       currRow = currRow + currResults.getString(QueryColumns[0])+currResults.getString(QueryColumns[i][1])+"\n";
    entireQueryResults.append(currRow);
    Now, the problem is that there are columns in the queries that have digits, these can range from a single val to 5 and while 98% of them are 3 digits there are random instances where they are a single digit or even a -1. When this happens it throws the output way off and makes it difficult to read in the resulting email report.
    How can I incorporate this into a MessageFormat or ChoiceFormat object to make the output pretty ?

  • Formatting output values

    How can I format output money values to display 2 decimal digits ?
    For examole, for table values 1.20, 2.00 DBMS output displays 1.2 and 2. I want to display all missing zeroes.
    Thanks

    Use a format mask.
    SQL> select to_char(1.2,'999.99') from dual;
    TO_CHAR
    1.20
    SQL> select to_char(2.0,'999.99') from dual;
    TO_CHAR
    2.00

  • Formatted output with JAXB

    Hi, Please help me with the formatting of output XML file using JAXB. This is my client program that marshals xml content into xml file. This program is creating XML file with no indentation at all. I commented out the line
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    still getting same xml file with no indentation. Am I doing anything wrong?
    Thanks in advance.
    try {
    // create a Validator
    Validator v = jc.createValidator();
    // validate the content tree
    boolean valid = v.validate( root );
    //logger.info("XML File Validated Successfully" );
         Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://mydomain.com/Schemas/data DT.xsd");
    DataWriter writer = new DataWriter(
    new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8"),
    "UTF-8" );
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new NamespacePrefixMapperImpl());
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(root, writer);
    }catch( ValidationException ue ) {
    logger.error( "Caught ValidationException"+ue ); throw new SdarsDBException("Validation Exception "+ue);
    } catch( JAXBException je ) {
    je.printStackTrace();
    } catch( IOException ioe ) {
    ioe.printStackTrace();

    Hi,
    try writing to the FileOutputStream directly.
    I get formatted output this way.
    maybe the DataWriter is doinfg some translatiopn for you?
    Chris

  • Captivate MP4 format output

    Hi,
    I have generated the *.mp4 format output by using captivate 6.0. However, the output quality of the video is not satisfactory. The texts used in the demo are blurred and the image clarity is also not as expected.
    Can someone please help me out in generating a high quality video output.
    Thanks,
    Panendra

    OK.  Well that rules out one of the main reasons people see degradation in output quality,..resizing the content.
    My only other suggestion is that you may need to play around with the publishing settings in Captivate to see if changing something there will improve the quality.

  • COPA line item report, Number format  -output type - object list(ALV).

    Hi,
    I am preparing COPA line item report. I want to change number format (two decimal place). I did the changes in form level then I did the changes in drill down report as well and saved as save definition.
    But changes are not reflecting in- output type - object list(ALV).
    Please provide help in this.
    Regards

    HI
    What t-code you are using to write this line item report ?

Maybe you are looking for

  • How can I create template documents for non-InDesign users to edit the text of later?

    I'm looking to produce a small system for people within my company to edit and print labels as needed that comply with our internal design standards. I would like to use InDesign to produce a few templates for labels that people could then edit one o

  • Problems with rented movie

    I just rented a movie with my apple tv and it has no audio, the preview has audio but the movie doesn't.

  • From a small publisher.

    I own a Sony reader, Nook and Kindle. My published EBooks sell at B&N and Amazon, I would like to sell them at Sony's Estore. The problem is that Sony is small publisher or author hostile in its business setup. Smashwords conversion while nice is als

  • CRS Report Definition for Schema

    Hello, We have CRS installed and have defined some reports using the CRS client. It seems that when you define a report, the Oracle Schema is selected as part of the report itself, which is fine. Now we are trying to integrate our application with CR

  • Supressing message

    Hi all, my problem is: I have used a push button to populate record in a block; i have another push button to clear that clock before ay commit being made: IF :SYSTEM.RECORD_STATUS IN ('NEW', 'INSERT') THEN      Go_Block('mob_app_conditions');      C