Scientific notation and Java

Hi. I Have the following questions. Would appreciate any response.
I am using JDK 1.4.2
Reading an Excel file with POI from appache.
The spread sheet has mixed data, and text - no formulas, taht's taken care of
Because of the nature of the application environment, we don't know the datatype in a cell ahead of time, so If I spot a number I get a nueric type, if I spot a character stream - I get a string, etc. ... but at the end of the cycle, in the application domain I have everything as STRINGS.
Problem 1:
In Excel file I have a entry: A = 20385759367
In Java it comes as: A = 2.0385759367E10
Problem 2:
In Excel file I have a entry: A = 10
In Java it comes as: A=10.0
Is there some way, to get it reformated back to 20385759367, and to 10 without going through all kind of string patterning with substrings and recognizing "E" ect .... maybe there is a method in some class, that I don't know about ?

double a = 20385759367.0;
double b = 10.0;
double c = 0.34567;
java.text.NumberFormat f = new java.text.DecimalFormat("0.##");
System.out.println(a+" -> "+f.format(a));
System.out.println(b+" -> "+f.format(b));
System.out.println(c+" -> "+f.format(c));

Similar Messages

  • Scientific Notation in Java

    Hi,
    In the hopes of enforcing a precision of 1.0e-16 for all the doubles in my Java application, I am trying
    to apply a DecimalFormat pattern so that my doubles can be printed in scientific notation if necessary. I am doing:
    DecimalFormat decf = (DecimalFormat)DecimalFormat.getInstance();
    decf.applyPattern("0.################E0");
    as the first step in the execution process but this is not working. Am I missing something?
    Thanks,
    Corrine

    It might help if you explained what "not working" means in this case. You can only use formatting to control how the numbers appear to you, not how they are represented internally for calculation, if that's part of your question.

  • DecimalFormat scientific notation if necessary

    I would like to find a way to output a double value in a way that uses scientific notation only if the number of digits output would be at least 15. For instance, the value 12345000000000000 should be output as 1.2345E16, but 12345000 would not be output in scientific notation (and the same logic if the value is < 0). Is this possible with the DecimalFormat class?
    I tried using String.format("%.15g", value), but that always displays trailing 0s to fill the significant digits (e.g. 12.345 outputs "12.3450000000000"). I don't want it to output the trailing 0s.

    I would like to find a way to output a double value
    in a way that uses scientific notation only if the
    number of digits output would be at least 15. For
    instance, the value 12345000000000000 should be
    output as 1.2345E16, but 12345000 would not be output
    in scientific notation (and the same logic if the
    value is < 0). Is this possible with the
    DecimalFormat class?
    I tried using String.format("%.15g", value), but that
    always displays trailing 0s to fill the significant
    digits (e.g. 12.345 outputs "12.3450000000000"). I
    don't want it to output the trailing 0s.With DecimalFormat ( http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html )
    you can format the number in scientific notation but to control which numbers are formatted I think you must write some sort of if else

  • Select Query resulting in Scientific Notation

    Hello all,
    I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
    select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
    I apologize in advance if this has been answered already.
    Thanks!

    >
    When the extractor finishes, it returns the data into a flat file.
    don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
    >
    Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
    Here is how sql*plus (Oracle's tool) will display the data using default settings
    SQL> select 12345678901234567890123456789012345678 no_format,
      2  to_char(12345678901234567890123456789012345678, '99999999999999999999999999
    999999999999') with_format
      3   from dual;
    NO_FORMAT WITH_FORMAT
    1.2346E+37  12345678901234567890123456789012345678
    SQL>
    ----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
    NO_FORMAT,WITH_FORMAT
    1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string.

  • BIGINT in scientific notation

    Hi,
    New here and new to CF8. I'm using MySQL 5.0.51b with the
    latest JDBC connector and am getting unsigned BIGINT columns larger
    than 10^12 back in scientific notation instead of a whole number.
    Here's an example:
    <cfquery name="get_bigint" datasource="ds">
    select cuid,convert(cuid,signed) as c_cuid
    from ctable
    where id=17
    </cfquery>
    <cfdump var="#get_bigint#">
    cuid is an unsigned BIGINT in ctable. In the CF dump, cuid is
    displayed in scientific notation and c_cuid is displayed as a whole
    number. If I try to use cuid, say as a URL parameter, it also ends
    up in scientific notation, which is obviously undesirable. Is there
    a configuration setting I need to change somewhere or is the CF /
    JDBC way to deal with this to use CAST / CONVERT on BIGINT columns
    to ensure they stay in whole number format?
    Thanks

    Hi,
    the function FIXED (<your expression>, <number of digits) may help
    Elke

  • Remove scientific notation in report

    I'm calculating a number and placing it in a comment box on a report. This works fine, but one of the numbers has decided to display in scientific notation (1.52666667e-3). The problem is that the comment box is not large enough to display the scientific notation and gives no indication of not fitting into the box. Instead I see 1.52666 with no indication of the exponent. I'd much rather see .001527 however I don't want to force a STR format with "d.dddddd" because most numbers don't need this much precision and I'd probably run into errors for numbers such as 12345 which won't fit into the comment box with forced 6 digit precision. If I can force it out of scientific precision, it'll probably be fine.
    BTW: is there a certain number range where scientific notation becomes the default? If I knew this range I could then force the format with the STR function to display the way I want. e.g. IF x>-001 and x<.001 then STR(X,"d.dddd")
    Either method would probably work for me.
    thanks,
    James
    Solved!
    Go to Solution.

    MyVar is a 2 dimensional pointer (Channel Group, Channel) to numeric channels that meet some criteria.
    change box size: I had to make the box 3 times the width to display the number correctly. It shows 1.27933333333333E-03*. I'm appending the "*" to show the field is calculated instead of unadultered from the .csv. Maybe the problem isn't that the number is small, but that it's infinitely repeating. The number is calculate from the values .001919 - abs(.001919)/3
    Left Justify: no difference from right justify.
    Autoadj: shows 1.28E-
    I'm making a column of channels on the report, that's why the comment text is being set multiple times.
    Humphreyy - thanks for your ideas and help.

  • Converting from a double to scientific notation

    does anyone know how I can convert a double value to scientific notation?

    java.text.DecimalFormat can do that.

  • Double and scientific notation

    Hi,
    I am using a Double to store data but when i output it the value
    is printed in scientific notation example, 2.3333E5..I want to print it as decimal without the 'E' notation, is there a way to format it or set the precision in Java???
    Many Thanks

    You can have a look at NumberFormat and also search this forum because it's a frequently asked question.

  • Numberformatter and scientific notation

    Hello all.  I'm having an issue with Numberformatter that I could use some assistance with.  It looks like this:
        <mx:NumberFormatter id="numberFormatter"
            precision="6"
            rounding="up"
            useThousandsSeparator="false"
            useNegativeSign="true"/>
    I'm applying it to a Number object that was created from a deserialized java BigDecimal.  In most cases, this is successful. So, 0.000024603877571 becomes 0.000025 and so on.
    However, in some cases, my Number is in scientific notation like "0E-15".  In this case, the NumberFormatter formats the number as -15.000000.  Not helpful.  Any ideas on what is going on and how I might could work around it?

    Thanks for the quick response, Michael.  I was about to simply change the sending of the numbers as a string when I decided to try one more thing.  If I use toFixed() on my number first (before the NumberFormatter.format() function) it seems to fix the issue.  So, for example, in my label function for a column of a datagrid that has Numbers that sometimes appear in scientific notation, I do something like this:
                public function myNumberLabelFunction(item:Object, column:DataGridColumn):String
                    var myNumber:Number = item.number;
                    var myNumberString:String = myNumber.toFixed(20);
                    return numberFormatter.format(myNumberString);
    That (toFixed) appears to not mess up the regular numbers as well as the ones that have E notation.  I don't know if anyone has any thoughts on the workaround.  It seems to work find since my formatter is ultimately rounding to a precison of 6.

  • Decimal Format and Scientific Notation

    I am trying to print numbers in scientific notation using the Decimal Format class. What follows is a simple test program I wrote to find the bug. So far, I have not found a solution.
    import java.text.*;
    public class formatted {
    public static void main (String Arguments[]) {
    DecimalFormat form = new DecimalFormat("0.###E0");
         double numb = 123456.789;
         System.out.println("Nuber is: " +
    form.format(numb));
    The output of this program is... Nuber is: 123456E
    The output is the same if numb is an int, float, or double. If I format the number as "#####.0" or "#####.00" the output is correct. I think that I am following the rules for formatting a number in scientific notation as the process is outlined in the documentation (provided below).
    ***** From Decimal Format under Scientific Notation ***
    Numbers in scientific notation are expressed as the product of a mantissa and a power of ten, for
    example, 1234 can be expressed as 1.234 x 10^3. The mantissa is often in the range 1.0 <= x < 10.0,
    but it need not be. DecimalFormat can be instructed to format and parse scientific notation only via a
    pattern; there is currently no factory method that creates a scientific notation format. In a pattern,
    the exponent character immediately followed by one or more digit characters indicates scientific
    notation. Example: "0.###E0" formats the number 1234 as "1.234E3".
    Anyone understand how the short program is incorrectly written?
    Marc

    The problem is
    format = "0.###E0"
    input number = 123456.789
    output = 123456E (not scientific notation!)
    This is not scientific notation at all. There is no decimal point given and no value in the exponent.
    I understand entirely that by adding more #'es will provide more precision. The bug I have is the output is not printed in the scientific format; other formats work.
    MArc

  • External table.How to load numbers (decimal and scientific notation format)

    Hi all, I need to load inside an external table records that contain 7 fields. The last field is called AMOUNT and it's represented in some records with the decimal format, in others records with the scientific notation format as, for example, below:
    CY001_STATU;2009;Jan;11220020GR;'03900;CYZ900;-9,99999999839929e-03
    CY001_STATU;2009;Jan;11200100;'60800;CYZ900;41380,77
    The External table's script is the following:
    CREATE TABLE HYP_DATA
    COUNTRY VARCHAR2(50 BYTE),
    YEAR VARCHAR2(20 BYTE),
    PERIOD VARCHAR2(20 BYTE),
    ACCOUNT VARCHAR2(50 BYTE),
    DEPT VARCHAR2(20 BYTE),
    ACTIVITY_LOC VARCHAR2(20 BYTE),
    AMOUNT VARCHAR2(50 BYTE)
    ORGANIZATION EXTERNAL
    ( TYPE ORACLE_LOADER
    DEFAULT DIRECTORY HYP_DATA_DIR
    ACCESS PARAMETERS
    ( RECORDS DELIMITED BY NEWLINE
    BADFILE 'HYP_BAD_DIR':'HYP_LOAD.bad'
    DISCARDFILE 'HYP_DISCARD_DIR':'HYP_LOAD.dsc'
    LOGFILE 'HYP_LOG_DIR':'HYP_LOAD.log'
    SKIP 0
    FIELDS TERMINATED BY ";"
    MISSING FIELD VALUES ARE NULL
    REJECT ROWS WITH ALL NULL FIELDS
    "COUNTRY" Char,
    "YEAR" Char,
    "PERIOD" Char,
    "ACCOUNT" Char,
    "DEPT" Char,
    "ACTIVITY_LOC" Char,
    "AMOUNT" Char
    LOCATION (HYP_DATA_DIR:'Total.txt')
    REJECT LIMIT UNLIMITED
    NOPARALLEL
    NOMONITORING;
    If, for the field AMOUNT I use the datatype VARCHAR (as above), the table is loaded but I have some records rejected, and all these records contain the last field AMOUNT with the scientific notation as:
    CY001_STATU;2009;Jan;11220020GR;'03900;CYZ900;-9,99999999839929e-03
    CY001_STATU;2009;Feb;11220020GR;'03900;CYZ900;-9,99999999839929e-03
    CY001_STATU;2009;Mar;11220020GR;'03900;CYZ900;-9,99999999839929e-03
    CY001_STATU;2009;Dec;11220020GR;'03900;CYZ900;-9,99999999839929e-03
    All the others records with a decimal AMOUNT are loaded correctly.
    So, my problem is that I NEED to load all the records (with the decimal and the scientific notation format) together (without records rejected), but I don't know which datatype I have to use for the AMOUNT field....
    Anybody has any idea ???
    Any help would be appreciated
    Thanks in advance
    Alex

    @OP,
    What version of Oracle are you using?
    Just cut'n'paste of you script and example woked FINE for me.
    however my quation is... An external table will LOAD all data or none at all. How are you validating/concluding that...
    I have some records rejected, and all these records contain the last field AMOUNT with the scientific notation
    select * from v$version where rownum <2;
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    select * from mydata;
    CY001_STATU     2009     Jan     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Feb     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Jan     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Jan     11200100     '60800     CYZ900     41380,77
    CY001_STATU     2009     Mar     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Dec     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Jan     11220020GR     '03900     CYZ900     -9,99999999839929e-03
    CY001_STATU     2009     Jan     11200100     '60800     CYZ900     41380,77MYDATA table script is...
    drop table mydata;
    CREATE TABLE mydata
    COUNTRY VARCHAR2(50 BYTE),
    YEAR VARCHAR2(20 BYTE),
    PERIOD VARCHAR2(20 BYTE),
    ACCOUNT VARCHAR2(50 BYTE),
    DEPT VARCHAR2(20 BYTE),
    ACTIVITY_LOC VARCHAR2(20 BYTE),
    AMOUNT VARCHAR2(50 BYTE)
    ORGANIZATION EXTERNAL
    ( TYPE ORACLE_LOADER
    DEFAULT DIRECTORY IN_DIR
    ACCESS PARAMETERS
    ( RECORDS DELIMITED BY NEWLINE
    BADFILE 'IN_DIR':'HYP_LOAD.bad'
    DISCARDFILE 'IN_DIR':'HYP_LOAD.dsc'
    LOGFILE 'IN_DIR':'HYP_LOAD.log'
    SKIP 0
    FIELDS TERMINATED BY ";"
    MISSING FIELD VALUES ARE NULL
    REJECT ROWS WITH ALL NULL FIELDS
    "COUNTRY" Char,
    "YEAR" Char,
    "PERIOD" Char,
    "ACCOUNT" Char,
    "DEPT" Char,
    "ACTIVITY_LOC" Char,
    "AMOUNT" Char
    LOCATION (IN_DIR:'total.txt')
    REJECT LIMIT UNLIMITED
    NOPARALLEL
    NOMONITORING;vr,
    Sudhakar B.

  • To_number and scientific notation

    Hi
    I am trying to convert a number in scientific notation stored in a character ffield to a number.
    I use this statement, but gets a ORA-01722 error.
    What is wrong ?
    select to_number('1.1111111111111112E-6','9.9EEEE')
    from dual
    Preben

    Hi guys, I'm following this forum in order to reuse what you wrote, but I still have a problem with the scientific notation format...
    From SQL Plus If I run this query:
    select b.CONTRACT_NUMBER,b.id as cont_id from OKC_K_HEADERS_B b--, okc_k_lines_b v
    where b.contract_number = 'NR19Mini'
    I retrieve the following row:
    CONTRACT_NUMBER                       CONT_ID
    NR19Mini                           1.4733E+38where the CONT_ID datatype is NUMBER.
    Now I want to specify a condition using the CONT_ID field (for another use in the future), but if I use the following syntax
    select b.CONTRACT_NUMBER,b.id as cont_id from OKC_K_HEADERS_B b
    where b.contract_number = 'NR19Mini'
    and b.id = to_number('1.4733E+38','9.99999EEEE');
    I don't retrieve any rows (no rows selected)
    How can I modify the format number in order to see my row, and for example use it inside a join with another fied of the same type ?
    Thanks in advance
    Alex

  • Numeric value and scientific notation

    Hi,
    with Oracle 8 or 10, the query (via TOAD or my app : Delphi + BDE)
    SELECT 0.0008 FROM DUAL returns 0.0008,
    but the query
    SELECT 0.00008 FROM DUAL returns 8E-5.
    Is there a way to avoid this display in scientific notation, except changing all my queries ? Or to push the limit for this display one digit later ?
    Maybe with an Oracle parameter ?
    Thanks for your help !

    duplicate for thread
    numeric value and scientific notation

  • Calculator and Scientific Notation

    My Calculator App seems to randomly switch back to scientific notation instead of displaying results in regular x.xx format.
    I tried deleting the com.apple.calculator.plist file and then relaunching Calculator but that didn't work.
    Any other suggestions on how to get the calculator app back to displaying results in normal (non-scientific notation) mode?
    thanks

    Then, I'm at a loss. Mine only shows scientific notation when the value exceeds whatever's set as the number's max range. You might want to peruse Calculator's help files.

  • Calculator.app Version 4.5.3 (99.2) and Scientific Notation

    I want to enter a number with scientific notation.
    2.71e1 doesn't return 27.1, but rather 0.999...
    It seems that Calculator.app is dividing by e.
    This is not a common operation.
    2.71E1 gives 27.1great! But ...
    2.71E-1 does not return 0.271 neither does
    2.71E(-1)
    I have yet to figure out how to use negative exponents in Scientific notation.
    This seems to be a bug in Calculator.app Version 4.5.3 (99.2)

    All my spaces were deleted.
    Take two.
    My input ======= Calculator
    2 ============ 2
    2. ============ 2.
    2.7 =========== 2.7
    2.7E ========== 2.7 E 0
    2.7E- ========== 2.7 (and the small - subscript indicating a negative number)
    2.7E-1 ========= 1 (and the small - subscript indicating a negative number)
    Now hitting enter === 1.7 (it appears to have subtracted 1 from 2.7)
    Do our version of Calculator match?
    Thanks for being interested.

Maybe you are looking for