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.

Similar Messages

  • 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

  • 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 Int/Double to Wording Format

    Hi,
    Does anyone has any sample program to convert double values into wording (this functionality is used to convert currency value) up to Trillion value.
    For eg: 1000.90 One thousand And Ninety Cents
    I have written a program which can accept up to 1 Billion. This is because that 'int' can accept bits up to that level only. I am unsure how go beyond that because when I declare the type to double, the compiler gave me the same error.
    Thank you.

    Check
    http://www.rgagnon.com/javadetails/java-0426.html
    but consider keeping locale specific texts in properties
    file and access them through resource bundles.

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

  • 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

  • Convert from scientific notation

    Can someone help me with this? I cannot get this working even using some of the tips I found on this site and elsewhere:
    Round this and format this with 2 decimals: '-2.58069E-11'.
    Now I realize this would end up -2.58, but it is giving me an error instead.
    Error converting data type varchar to numeric.
    SELECT CAST('2.58069E-11' AS NUMERIC(24,2))
    SELECT CAST('2.58069E-11' AS NUMERIC(24,12))
    I tried 12 just to make sure that there was enough room for the decimals
    If I use ISNUMERIC, it returns 1, so SQL Server considers it a number (at least with that function)
    The next example works, but it is not what I want.
    SELECT CAST('2.58069E-11' AS REAL) just returns the same thing with the 'E', (as REAL, of course)
    In these example I haven't done the rounding yet.
    I get all kinds of negative and positive numbers with different decimal lengths, but the scientific notation is particularly tricky.

    Before I put this to bed, I have found out both the above solutions are wrong when using a regular decimal:
    Try this:
    SELECT CAST(CAST('-1131658.27' AS REAL) AS NUMERIC(24,2))
    And this:
    SELECT CAST(CONVERT(REAL, -1131658.27) as DECIMAL(24,12))
    They both yield -1131658.25, and -1131658.250000000000, respectively.
    This is probably some floating point error, but how do I take care of it?

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

  • Numeric Values Converted to Scientific Notation

    My BPEL process converts numeric values to scientific notation (eg. 12345678 is converted to 1.2345678E7). This then causes problems when I try to perform any mathematical operations on these values during an XSL transformation (output - NaN)
    Is there any way I can stop this data conversion?
    This occurs with BPEL 10.1.2.0.2. I'm loading the data from an Oracle 9.2 database using the DbAdapter.
    I've written an XSL routine to convert these values back to the correct decimal notation, but would prefer to stop this happening rather than workaround the problem.

    On further investigation, this occurs for values loaded from Oracle FLOAT database type.
    The XSD generated for the DbAdapter uses type xs:double for this field, but I've also tried changing this to xs:decimal & xs:float and still get the same problem.

  • 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

  • Converting scientific notation string to number?

    This is raising an error:
    > ToNumber (u201C2.75E-05u201D)
    How do you convert scientific notation strings to numbers?
    This is coming from XML. I can probably have the XML written so that it's not scientific notation.
    Tim

    Here's a not-so-pretty way:
    Local StringVar Array x;
    Local StringVar mantissa;
    Local StringVar exponent := "0";
    // Split into mantissa and exponent parts.
    x:= Split("24.2233E+2", "e", 2, 1);
    mantissa := x[1];
    If (UBound(x) = 2)
    Then
        exponent := x[2];
    // CDbl cannot interpret leading positive sign, so removie
    If Left(mantissa, 1) = "+"
    Then
        mantissa := Right(mantissa, Length(mantissa) - 1);
    If Left(exponent, 1) = "+"
    Then
        exponent := Right(exponent, Length(exponent) - 1);
    // Compute number
    CDbl(mantissa) * 10 ^ CDbl(exponent);
    Sincerely,
    Ted Ueda

  • Data retrieval in non-scientific notation from Netezza database

    Hi,
    I have a requirement where my BPEL service fetches data from Netezza database. In the database, there is a field which is of type numeric(16,8) and holds values say '0.00000000'. The select query on the table rerieves data in its scientific notation as '0E-8'.
    Please let me know how to retrieve its value in the form of non-scientific notation.
    Thanks in advance.
    Regards,
    Sitara

    hai
      chowdary,
       it is not possible to retrieve data from maintenace view.
    it is only possible to retrive data from a table or database
    / projection views defined ddic.
    Maintenace views are used to maintain data of an application object together.Data from several tables can be joined and summarized data can be seen of this view based on primary key join relationship using SM30.U make any changes  or view the data there only.
    if useful, reward points.
    By
    G.V.K.Prasad
    Edited by: PRASAD GVK on Apr 13, 2008 3:36 PM

  • Convert Scientific Notation to Float

    Hello
    How can we convert Scientific notation to float.
    e.g.
    1.23E-3(string) as  0.00123(float)
    Thanks
    Solved!
    Go to Solution.

    Use Fract/EngStringToNumber. Or ScanFromString with format %f…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Prevent large numbers from becoming scientific notation on CSV import

    Hi, I'm importing contacts in a .CSV file into iWork Numbers and it takes a 12-digit phone number from a guy in the UK and turns it into scientific notation. So something like 447729803988 becomes 4.4772E+11 which obviously loses some important digits. Is there a way to force Numbers to treat all fields as text on import so it doesn't drop this critical data? thanks
    Sean

    scrollin,
    Your digits are all there. Just format those cells to either Text or Number. Leading zeros do tend to get lost unless you pre-format to text. You can force the cell format to text on the fly by prefixing your input with a single-quote.
    Regards,
    Jerry

  • Convert from Comma notation to Decimal Notation, Any FM ?

    Hi Experts,
    I am looking to convert from Europe format to US format for Quantity & amount fields, I mean
    e.g. Europe:  12.3456,78 -> US: 12,3456.78
    pls. i can not use offsetting, replace, pattern, overlay, concatenate etc.
    So, pls. let me know that, Is there any SAP FM for this purpose of DECIMAL NOTATION conversion?
    thanq
    Edited by: Srinivas on Feb 22, 2008 10:48 PM

    use.
    Replace all occurances of ',' in w_value with '.'.
    Check this thread.
    REgarding converting  ','  TO  '.'

Maybe you are looking for

  • An active component in a JCombobox

    I placed an own component, used to select a date in, a JComboBox, no problem so far. I wrote a simple renderer, place the component on a JPanel � works fine. Now my problem: If I click on the component, the JCombobox closes immediately. No mouse-clic

  • I'm frustrated! :-( Connecting a Roland piano to my MacBook Pro via Firebox

    I need some help as I am having someone come to record a song for me tomorrow on my Roland. I have a Roland piano with an audio out 1/4 inch cable. I have connected it to my Presonus Firebox in Line In port 3. I have connected the firewire cable. I b

  • The "Null Error Stack"  that is shown in the Run time workbench

    The Data is set to flow from SAP R/3 system to target system through XI. When the data is triggered in the SAP system, the same data is getting updated in the target system database. But when i check in the Run time workbench for the same, in the act

  • Factory preset for imac

    i have just bought a brand new imac intel.it was the display model and i want to know how to reset the settings back to the factory standard.someone has configured passwords etc on it that i cant get rid off. can anyone help me please. I want it to s

  • Can you add Geo Tags to images you shoot in Adobe Bridge?

    I was wondering if this could be done? -David