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

Similar Messages

  • 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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.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.

  • Float Data Value and Scientific Notation

    Hello All,
    SQL Server converts some of the float value into scientific notation for example 0.00001 will be stored as
    1E-05.
    Is there any simple method\formula\threshold to precisely tell when some particular value will be converted to scientific notation?
    Also I think oracle store same value above i.e. 0.00001 as it is with float data type but not the case with SQL Server. Any reason for the same?
    Thanks in Advance.
    -Malkesh

    Thanks Erland.
    I got your point that internal storage as you mentioned will be 53 bit and 11 bit exponent of 2. However my question remains the same that is there any method\threshold from which we can say that after this numeric value stored data will be represented in
    scientific notation or any rule of thumb? For example
    drop
    table #t
    CREATE
    TABLE #T (T1
    FLOAT)
    INSERT
    INTO #T (T1)
    SELECT 0.000001
    INSERT
    INTO #T (T1)
    SELECT 0.00001
    INSERT
    INTO #T (T1)
    SELECT 0.0001
    INSERT
    INTO #T (T1)
    SELECT 0.001
    INSERT
    INTO #T (T1)
    SELECT 0.01
    INSERT
    INTO #T (T1)
    SELECT 0.1
    INSERT
    INTO #T (T1)
    SELECT 1.
    INSERT
    INTO #T (T1)
    SELECT 1.0
    INSERT
    INTO #T (T1)
    SELECT 1.01
    INSERT
    INTO #T (T1)
    SELECT 1.001
    INSERT
    INTO #T (T1)
    SELECT 1.0001
    INSERT
    INTO #T (T1)
    SELECT 1.00001
    INSERT
    INTO #T (T1)
    SELECT 1.000001
    INSERT
    INTO #T (T1)
    SELECT 1.0000001
    INSERT
    INTO #T (T1)
    SELECT 1.00000001
    INSERT
    INTO #T (T1)
    SELECT 1.000000001
    INSERT
    INTO #T (T1)
    SELECT 1.0000000001
    INSERT
    INTO #T (T1)
    SELECT 1.00000000001
    INSERT
    INTO #T (T1)
    SELECT 1.000000000001
    INSERT
    INTO #T (T1)
    SELECT 1.1
    INSERT
    INTO #T (T1)
    SELECT 10.1
    INSERT
    INTO #T (T1)
    SELECT 100.1
    INSERT
    INTO #T (T1)
    SELECT 1000.1
    INSERT
    INTO #T (T1)
    SELECT 10000.1
    INSERT
    INTO #T (T1)
    SELECT 100000.1
    INSERT
    INTO #T (T1)
    SELECT 1000000.1
    INSERT
    INTO #T (T1)
    SELECT 10000000.1
    INSERT
    INTO #T (T1)
    SELECT 100000000.1
    INSERT
    INTO #T (T1)
    SELECT 1000000000.1
    INSERT
    INTO #T (T1)
    SELECT 10000000000.1
    INSERT
    INTO #T (T1)
    SELECT 100000000000.1
    INSERT
    INTO #T (T1)
    SELECT 1000000000000.1
    SELECT T1
    FROM #T
    Here you can see value < 0.0001 i.e. 0.00001 and 0.000001 both are in scientific notation. So which rule or formula drives this behavior that is what my question is. Sorry I am somewhat poor in mathematics fundamentals So if you can make it simple.
    Thanks Again.

  • Iphone and Scientific Notation

    I have a problem with my new iphone's calculator. When I go to the scientific calculator it does not go into scientific notation mode. I could have sworn that when I was at the apple store a month ago that the same calculator on the floor that I checked out went into scientific notation when I rotated it.
    the tech on the help line did not even know what scientific notation was---am I missing something here? or does my iphone have a glitch? ( I have version 2.02 on it.)

    It still does when the full width of digits is exceeded, but in landscape mode that's a lot of digits!

  • Scientific notation in numeric fields

    I need to be able to input scientific notation in numeric fields for my adobe forms.  I can put the pattern to num{9.99E} and it will allow me to put positive exponents and negative exponents to -3.  However, I need to input the number 4.76E-19 and it always changes it to 0.00E0.  What kind I do to keep this small of a number as 4.76E-19?

    Hi,
    Unfortunatly in approach with text field numbers will not be formatted in scientific  notation, users will have to type numbers in correct format.
    In approach with NumericField and patter {9.99E} i think there is some bug.
    I can type this number:
    After i lost focus from this field it will be formatted in tis style:
    And sfter button click i will get this:
    For big values everything working fine.
    Is this bug!?
    BR

  • Rounding with decimal format

    im trying to use decimal format and at the same time round numbers
    code:
    dformat = new DecimalFormat("0.0");
    test = dformat.format(num);
    but if num is .65 it just shows .6 when i need it to be .7
    any suggestions.
    thanks

    because it uses BigDecimal.ROUND_HALF_EVEN rounding mode, as per the API docs saying so......
    ... of course, for the life of me (I blame it on Monday.... yes, I know it's not Monday.... still) I can't remember the right way to do it..........
    sorry..
    brain freeze warning...
    must go home and reboot....

  • Powershell / Scientific Notation Woes / Formatting Output to Live Excel Sheet

    I have a WMI query in a script that dumps machine information to a live excel sheet.
    I find when I query the model # of the machine using (this line of code from the script):
    $Sheet.Cells.Item($count,4) = (Get-WmiObject win32_computersystem -ComputerName $computer).Model
    The output almost always changes into Scientific Notation, because this is a typical model number :   "3500-E52"
    Is there a way to modify the formatting of the:
    $Sheet.Cells.Item($count,4)
    so that Excel uses "text" formatting for that cell?  I know you can change the fonts etc... but have not been lucky in finding a powershell > excel reference
    that explains how to change a cell or column's formatting beyond the basics.
    I have seen recommendations to others to dump the results queries to a CSV first, and then import into Excel (which would allow a manual change of that column's format).  I'm just
    hoping to bypass the extra "hands on" and format more directly to a sheet in Excel.
    If .csv is the best way to go, I'll muddle through it and change the code.
    Any help is greatly appreciated.
    Ben

    $sheet.Cells(1,1).NumberFormat
    = "@"
    ¯\_(ツ)_/¯

  • Importing data in scientific notation format

    Hi,
    I've got some data files produced by some ancient laboratory software. In the files, numbers are formatted like this:
    +7.60609E-02
    +8.18901E-03
    etc.
    When I import the data into Numbers, Numbers does not seem to recognize that the data points represent numbers, rather than strings (I can't create plots from the data, for example). If I edit the cells to prepend "=" to the entry, then Numbers evaluates the entry as if it were scientific notation (which is what I want), so that +7.60609E-02 becomes 0.760609. Is there a way to indicate to Numbers that the data I am importing is in scientific notation format, and should be treated as such? Because I'm not too excited about manually prepending "=" to everything.
    Thanks

    If the file is a comma separated values file, you have two choices:
    1) Make a Numbers sheet that is formatted the way you want it, including formatting the cells in the column to be scientific.  Drag the file from Finder and drop it on cell A1 of the table or, if not A1, the top-left cell of where you wantthe data to begin in the table, like maybe cell B2. Or,
    2) Open the CSV file with Numbers. After import, select the column of numbers and format it as scientific.

  • Formating scientific notation

    Hi,
    I'm working with a small program where at one point a number, in scientific notation will need to be formated into a string containing plane numbers.
    I use the code below, and it works in up to large numbers where the formatting doesen't do aything at all.
    String InputValue = "7,584995286E7";
    NumberFormat format = NumberFormat.getNumberInstance();
    Number number = format.parse(InputValue);
    String OutputValue = number.toString();
    System.out.println(OutputValue);The example above gives the result input back as output value: 7.584995286E7
    With the value 7,584995286E6 the result is: 7584995.286 just as I want it to work.
    What can I do to solve this?
    All help is appreciated.
    Thanks
    /H�kan

    Hi ,
    Below is the code posted by you.
    String InputValue = "7,584995286E7";
    NumberFormat format = NumberFormat.getNumberInstance();
    Number number = format.parse(InputValue);
    String OutputValue = number.toString();
    System.out.println(OutputValue);Add these two methods, and you will get the code working as you needed.
    format .setMaximumFractionDigits(3)
    format .setMinimumFractionDigits(3);
    Best regards
    Aneesh A.V

Maybe you are looking for

  • In my Itunes page the add play list and all other buttons are missing

    In my Itunes the add play list button and all others at the buttom of the page are not visiable hos anyone else run into this problem?

  • Image search results?

    I'm wondering if this typical image page from this web site would appear in Google image results. Should an H1 be added or anything else to the page. Could the caption be an H1? http://dankennedy.ca/images/dust_of_oblivion/thousands-of-mules.html

  • Last Purchase Order & GRN Price

    HI, Anybody can tell me, inwhich table can able to find the Last Purchase Order Price and GRN price. Tks Mani.

  • Sysssislog got created as a regular rather than a system table

    Hi. we run 2012 enterprise.  I believe some testing I did on a new pkg recently created dbo.sysssislog (may have looked to sql like it was first time and it needed to create a new one) in the tables folder rather than tables\system tables folder.  Bu

  • Printing dynamic documents

    Hi, I was using dynamic documents for creating tables and forms. I used the print_document command for printing the tables. The problem is that the document does not print from my machine but I could print it from 3 other machines. Is there any speci