Double in Scientific Notation after Marshal

Hi,
I have an element defined as an xsd:double. If I try and place a value say 100 into the element and then I marshal it I get an output of <Quantity>100.0</Quantity>... That is fine....
However, if I put a value in of say 1000000000, I get an output of <Quantity>1.0E9</Quantity> when I marshal.
Can I turn a setting on (or off) so the output does not get converted into scientific notation?
-j

I also verified the XML standard and you are right that the values are legal xsd:double values. What made this a problem for me is that the XSLT functions that use XPATH number() to process these values failed because XPATH specifies that a number is:
Number ::= Digits ( '.' Digits?)? | '.' Digits
which does not handle the exponents at all. So the XML documents produced could not be handled by XSLT processors.
For fun, I redefined my schema definition to replace xsd:double with:
<xs:simpleType name="simpleDouble">
     <xs:restriction base="xs:double">
          <xs:pattern value="(-)?[0-9]*(.[0-9]+)?" />
     </xs:restriction>
</xs:simpleType>
which is essentially a non-exponent based double. JAXB rendered the document, but then the validator complained that the output did not match the pattern. So JAXB does not use this pattern as a method of determining output, only as a method of validation.
This is why I replaced the DoubleType class for my solution. The alternative of using the jaxb:globalBindings is probably a cleaner approach. I think I'll switch my implementation. Thanks for the pointer!
-Allan

Similar Messages

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

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

  • Formatting Doubles with Scientific Notation Depending on Exponent Size

    Hi there. I was just wondering if there was a better way to do the following:
    DecimalFormat fmt;
    if (v>=1.0E9 || v<=-1.0E9 || (v>-1.0E-8 && v<1.0E-8 && v!=0.0 && v!=-0.0))
         fmt = new DecimalFormat("0.########E0");
    else fmt = new DecimalFormat("0.########");
    return fmt.format(v);

    I'm not an expert on DecimalFormat, so I may have missed something, but the only improvement I can see is to remove the v!=-0.0 check. 0.0==-0.0, so it's unnecessary.

  • Double.parseDouble(String) - problems when string is in scientific notation

    Hello guys,
    I'm doing some numerical calculations and I wonder whether it is possible for Double.parseDouble(String) to parse string in the scientific notation i.e. 1.0824234234E-10. Is it the notation itself causing the exception : NumberFormatException or the number is just too big/small and double can't hold it ?
    If it's just the notation how can I fix it ?
    Regards

    i'm not quite sure whether double odoes not allow it.
    perhaps consider the api Double.valueOf() and the testing code provided; reproduced below:To avoid calling this method on a invalid string and having a NumberFormatException be thrown, the regular expression below can be used to screen the input string:
            final String Digits     = "(\\p{Digit}+)";
      final String HexDigits  = "(\\p{XDigit}+)";
            // an exponent is 'e' or 'E' followed by an optionally
            // signed decimal integer.
            final String Exp        = "[eE][+-]?"+Digits;
            final String fpRegex    =
                ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
                 "[+-]?(" + // Optional sign character
                 "NaN|" +           // "NaN" string
                 "Infinity|" +      // "Infinity" string
                 // A decimal floating-point string representing a finite positive
                 // number without a leading sign has at most five basic pieces:
                 // Digits . Digits ExponentPart FloatTypeSuffix
                 // Since this method allows integer-only strings as input
                 // in addition to strings of floating-point literals, the
                 // two sub-patterns below are simplifications of the grammar
                 // productions from the Java Language Specification, 2nd
                 // edition, section 3.10.2.
                 // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
                 "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
                 // . Digits ExponentPart_opt FloatTypeSuffix_opt
                 "(\\.("+Digits+")("+Exp+")?)|"+
           // Hexadecimal strings
           "((" +
            // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
            "(0[xX]" + HexDigits + "(\\.)?)|" +
            // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
            "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
            ")[pP][+-]?" + Digits + "))" +
                 "[fFdD]?))" +
                 "[\\x00-\\x20]*");// Optional trailing "whitespace"
      if (Pattern.matches(fpRegex, myString))
                Double.valueOf(myString); // Will not throw NumberFormatException
            else {
                // Perform suitable alternative action
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html

  • Create an NSString for number in scientific notation from double?

    Hi
    Given a double, I want to create a string in scientific notation.
    e.g for a double with a value of 123.456, I want the NSString to be "1.23456e+2" for entering in to a UITextField.
    I've looked through the docs but can't find a formatter. (There is mention of "%a" being scientific format, but it produces hex output.)
    Thanks for any clues.
    Steve

    Here, you should find what you are looking for:
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
    http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/ Classes/NSStringClass/Reference/NSString.html#//appleref/occ/clm/NSString/stringWithFormat:

  • How can I get Numbers 3.2 to recognise 1e-5 as scientific notation?

    I just changed from Numbers '09 (2.3) to Number 3.2 on Mavericks (OS X 10.9.3) and the new version doesn't seem to recognise "e" or "E" as scientific notation. When I set the cell format to scientific and type "0.0015", Numbers returns "1.5×10^-03". I would however prefer to obtain "1.5e-3". And vice versa: if, after setting the cell format to scientific, I type "1.5e-3", it automatically formats the cell as text and I can't get it to recognise it as scientific notation. With "E" instead of "e", the problem is exactly the same. Does anyone know how I can change this setting? I already tried to search for an answer to my question, but couldn't find anything...

    if, after setting the cell format to scientific, I type "1.5e-3", it automatically formats the cell as text and I can't get it to recognise it as scientific notation.
    I can't duplicate the problem here, either when the cells are formatted as Automatic or as Scientific:
    When you type 1.5e-3 are you making sure not to enter a space after the e?  (When I type a space the cell automatically formats as Text.)
    SG

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

  • Scientific Notation to Integer?

    I have a string like 1.780657E7 that I need to convert to an integer. I think that might be too big for Integer, so maybe BigInt would be better.
    Anyway, I can't figure out how to do this! I guess I could write my own method, but I'm sure it's already out there somewhere. I'm pretty new to Java.
    Thanks a lot,
    - Andrew.

    A small exegesis of prometheuzz's perfectly accurate, if slightly terse solution.
    Scientific notation is assumed to be floating-point. You must therefore parse a scientific-notation string using Float.parseFloat() or Double.parseDouble() and "integerise" the result if an integer is what you want.
    The last line is to show that your sample number is easy to fit in an int variable.

  • 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

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

  • How to prevent display in scientific notation

    I want to convert a large double value to a string,
    but when the value is greater than 10000000 , it will display in
    scientific notation , such as 3.435E8
    However, how can I convert it automatically to 343500000 because
    there is an interface program which do not accept the scientific
    notation format
    Thanks in advanced

    Start here: http://java.sun.com/j2se/1.4/docs/api/java/text/NumberFormat.html

  • Problem: program outputs numbers in scientific notation

    my problem is that my program outputs the population in scientific notation instead of round the number to the nearest one. ex: it should say 30787949.57 instead of 3.078794957 E7
    // Calculates the poulation of Mexico City from 1995 to 2018.
    // displays the year and population
    class PopulationCalculator {
    static double r2(double x) {
         //this method rounds a double value to two decimal places.
    double z=((double)(Math.round(x*100)))/100;
    return z;
    } //end method r2
    public static void main(String args[]) {
         double population=15600000.0;
         double rate=0.03;
         System.out.println("Mexico City Population, rate="+r2(rate));
         System.out.println("Year    Population");
         for (int year=1995; year<=2018;year++)  {
             System.out.println(year+ "    "+r2(population));
        population+=rate*population;
        }//end for loop
        System.out.println("The population of Mexico City reaches 30 million on 02/13/17 at 5:38:34am");
        }//end main
        }//end PopulationCalculator
    {code/]

A: problem: program outputs numbers in scientific notation

Or upgrade to JDK 5.0 and user the new java.util.Formatter capability.
You control the rounding and get localization of the fomatted string at
no extra charge. A quick example:
class A {
    public static void main(String[] args) {
        double d = 30787949.57d;
        System.out.println(java.lang.String.format("%,17.2f", d));
}Example output for three different locales:
$ javac -g A.java
$ LC_ALL=fr_FR   java A
    30 787 949,57
$ LC_ALL=en_NZ   java A
    30,787,949.57
$ LC_ALL=it_IT     java A
    30.787.949,57For more information, refer to:
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#formatter

Or upgrade to JDK 5.0 and user the new java.util.Formatter capability.
You control the rounding and get localization of the fomatted string at
no extra charge. A quick example:
class A {
    public static void main(String[] args) {
        double d = 30787949.57d;
        System.out.println(java.lang.String.format("%,17.2f", d));
}Example output for three different locales:
$ javac -g A.java
$ LC_ALL=fr_FR   java A
    30 787 949,57
$ LC_ALL=en_NZ   java A
    30,787,949.57
$ LC_ALL=it_IT     java A
    30.787.949,57For more information, refer to:
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#formatter

  • 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

  • Displaying Scientific Notation

    I see a lot of people asking questions about how to prevent showing Scientific Notation.  I have the opposite problem, I can't seem to show scientific notation.
    In the field I'll Enter: 2.5E-5
    After commit, the value show: 0
    If I look in the database, it shows: 0.000027
    How can I get the form to show 2.5E-5?
    My Entity Attribute:
      <Attribute
        Name="Stock"
        ColumnName="STOCK"
        SQLType="NUMERIC"
        Type="oracle.jbo.domain.Number"
        ColumnType="NUMBER"
        TableName="WASTE_STREAM_NUCLIDE">
        <Properties>
          <SchemaBasedProperties>
            <DISPLAYWIDTH Value="8"/>
          </SchemaBasedProperties>
        </Properties>
      </Attribute>
    My Field on the Page:
                    <af:inputText value="#{bindings.Stock.inputValue}" label="#{bindings.Stock.hints.label}"
                                  required="#{bindings.Stock.hints.mandatory}"
                                  columns="#{bindings.Stock.hints.displayWidth}"
                                  maximumLength="#{bindings.Stock.hints.precision}"
                                  shortDesc="#{bindings.Stock.hints.tooltip}" id="it2">
                        <af:convertNumber groupingUsed="false" pattern="0.######E0"/>
                    </af:inputText>

    Good point. If everyone having problems with SQL*Plus number formatting went to the free online HTML manual, looked for "NUMBER" in the index and found
        NUMBER
            column definition from DESCRIBE, 12
        NUMBER clause, 5.12.2
            VARIABLE command, 12
        NUMBER columns
            changing format, 6.1.2.1, 12
            default format, 6.1.2.1, 12
        number formats
            $, 6.1.2.2
            0, 6.1.2.2
            9, 6.1.2.2
            comma, 6.1.2.2
            setting default, 5.9.4, 5.9.4, 12, 12
        NUMFORMAT clause
            in LOGIN.SQL, 2.2.2.1
        NUMFORMAT variable, 12, 12
        NUMWIDTH variable, 12, 12
            effect on NUMBER column format, 6.1.2.1, 12then we'd have nothing to do.

  • Maybe you are looking for

    • Dynamic sql and cursors

      We are running an oracle sql procedure that uses a LOT of dynamic sql. We are using a 3rd party package (SQR) as a sort of shell to run the sql procedure. The 3rd party package passes to us an oracle error. This error says, in effect, that there are

    • Setting Name of Loaded Movie Clips

      I'm getting this error after I use the loader to load in an swf- and then try to rename it to something useful. Error #2078: The name property of a Timeline-placed object cannot be modified. This is a new one - this means that I cannot rename a loade

    • XSAN in two buildings

      Has anyone setup XSAN in two different buildings/locations? We are looking to setup XSAN but we may be splitting into two locations. I've call our ISP providers and they said they could do a point to point DS3 but that would only get us 90mb max. The

    • Apple's "Backup" verses Time Machine?

      I have several external drives, USB and Firewire, that I created backups on for specific folders as well as my home folder and library, etc. This was while I was in Tiger. I recently upgraded to Leopard. I'm not sure what to do with my "Backup" backu

    • Resizing drawing objects defies pixel snapping

      This happens mostly with drawing objects, and to a lesser degree with shapes. When resizing drawing objects in Flash CS6 with pixel snapping turned on, one would expect the dimensions of the shape to snap to even pixel numbers. For the most part it d