Double.parseDouble returning 2.0E7

Hi,
I have a piece of code (snippet below)
double aggrAmount=0.0;
Tag t;
aggrAmount=Double.parseDouble(t.getValue().substring(t.getValue().lastIndexOf("/")+1, t.getValue().length()-1));
where t="AGGR//FAMT/20000000,"
when i check aggrAmount the value is 2.0E7. How can i get the value as it is?
PLs help...
THanks for your time and advice

when i check aggrAmount the value is 2.0E7. How can i get the value as it is?There's some confusion here between the value (a double value of twenty million), and the String you use to check it ("2.0E7"). They are different things.
If you want to see or use the value in a string without the exponent business, use String.format() or DecimalFormat. Note that the value remains what it is (twenty million); numbers don't have a format.
If you want the last part "as it is" ie as a String use String's lastIndexOf() and substring() methods and make value a String.

Similar Messages

  • Double.parseDouble

    the user enters a premium amount and then I want to use that amount in a calcuation; can't I parseDouble it like this? apparently not, because when I try to multiply, I get an error "the operator * is undefined for argument type(s) double, String. I have done this in the past, what is wrong?
    String pAmount = JOptionPane.showInputDialog("Enter the premium amount:");
    double num = EndCancelDiffCounter;
                   double denom = counter;
                   double result = num/denom;
                   Double.parseDouble(pAmount);
                   double refund = result * pAmount;

    parseDouble returns a double, it does not change the
    String given froma String to a double. You need to
    store that result (return value) in a new double
    variable and perform your calculation with that.
    Edit: Man I'm slow. (I had to check that
    parseDouble returned a double and not a Double. I
    wasn't 100% sure, as I'm a little daft this morning.)I see, thank you

  • What if Textfield t1 is blank?? num1=Double.parseDouble(t1.getText());

    Hi there
    Im coding a simple calculator with 2 Textfield for entering two numbers. If one of Textfields is blank and an operation button (+,-,*,/) is clciked, I want the 3rd Textfield t3 to read "ERROR".
    From the code below, what is num1 if t1 is blank. Or could you tell me how to go about this if statement.
    if (ae.getSource()==multi){
                   num1=Double.parseDouble(t1.getText());
                   num2=Double.parseDouble(t2.getText());
                   res=num1*num2;
                   t3.setText(""+res);
    cheers
    SERGIO

    I look forward to you figuring this out yourself.
    1. What does getText() return when then JTextField is empty?
    2. What happens when you pass that to parseDouble?
    3. Should you even bother passing that to parseDouble?

  • 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

  • Double.parseDouble(String) : Problem to parse large String

    Hello,
    I need to convert A String to a Double in my application without rounding of digits.
    I have used the Double.parseDouble(String) method.
    The maximum string length can be 17 including dot(.)
    So if my String is (of length 17)
    Eg.
    S= �9999999999.999999� then I am getting the double value as
    d= 9999999999.999998(compare the last digit)
    If s = �9999999999.111111� then d = 9999999999.111110
    If s = �9999999999.555555� then d = 9999999999.555555 (result that I want)
    If s = �9999999999.666666� then d = 9999999999.666666 (result that I want)
    If s = �9999999999.777777� then d = 9999999999.777777 (result that I want)
    If s = �9999999999.888888� then d = 9999999999.888887
    If s = �9999999999.999999� then d = 9999999999.999998
    If s = �9123456789.123456� then d = 9123456789.123456
    But string length up to 16 is giving me the accurate result
    So any body can explain me that why it is happening? And how can i get the accurate result.
    Thanks in advanced.

    Hi,
    Thank You for your suggestion. By which i can store
    the big double number in Data base , but at some
    point i require to parse a double value from a Double
    reference.In that case if the Decimal value length
    => 16 then it the last digit changes or rounds.
    coverting 9999999999.999999 Decimal value to double
    value. It gives me 9999999999.999998 and
    9999999999.9999999 gives me the 10000000000.0000000.
    but the Double value 999999999.999999 is ok
    and 999999999.99999999 rounds.Err, is there a follow up question in there?

  • Double.parseDouble help?

    I have this String Number 20.000. When I do a parseDouble I get 20.0 which is right.
    public class qwerty {
         public static void main(String[] args) {
              String num = "20.000";
              System.out.println(Double.parseDouble(num));
    But is there a way to preserve the zeroes and it prints 20.000 itself after parse Double?

    But is there a way to preserve the zeroes and it prints 20.000 itself after parse Double?Not directly. Doubles (and doubles, and all other Number subclasses and number primitives) store only information about the value of the number, not how it is to be displayed.
    As mentioned, you'll need to use formatting provided either by a DecimalFormat object or a printf() function. To do what you're asking, you'd need to somehow parse the input string to determine the required format, and store that information separately (e.g. in a String or a DecimalFormat object), then use that whenever you want to display the number. Check out the documentation for DecimalFormat and PrintStream.printf().
    Regex would probably be helpful if you decide to go that route.

  • Double.parseDouble() is not Locale specific, how do I get round this?

    I am parsing Strings into doubles using
    String myNumber = "12,34";
    double d = Double.parseDouble( myNumber );The problem is that my number is of French style (it has commas instead of fullstops for the decimal points)
    The default Locale is English, so I get NumberFormat problems when parsing. (I can understand this)
    I even get NumberFormat problems when I do this:
    Locale.setDefault(Locale.FRENCH);
    double d = Double.parseDouble( myNumber );Which I think is really strange. I guess the Locale of Double is set at a certain time and not reset.
    OR maybe Double.parseDouble( <STRING> ); is not Locale specific?
    Where is my understanding wrong?

    Do you know if DecimalFormat reflects the default Locale if the default Locale changes?
    Or will I have to make a new DecimalFormat whenever it changes?As Locale is invariant, a DecimalFormat instance (as well a any object with a reference to the default Locale) cannot reflect the default Locale changes.
    But each time you create a new instance of DecimalFormat without specifying the Locale, it will get up-to-date Locale.
    However, you might prefer setting the locale explicitely (instead of changing the default one.)
    Note that Double valueOf() or parseDouble() methods are not related to default Locale, they use a fixed format.

  • Double.parseDouble lost of precision!

    Hello,
    I have a small problem regarding convertion from string to double.
    double dTotal;
    dTotal = Double.parseDouble("10.01") + Double.parseDouble("0.12");
    Can someone explain me why my result is dTotal = 10.12999999999999 ?
    Thanks in advance.
    Remi.

    and read
    http://docs.sun.com/source/806-3568/ncg_goldberg.html
    This, too:http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2

  • Problem on Double.parseDouble

    Double.parseDouble(InputString); was error on my NetBeans 6.8 how to fixed it? I've tried to reinstall but still the same

    Make sure you are using CLDC 1.1. Double is not included in CLDC 1.0.
    Erik Wetterberg

  • Does browser support Double.parseDouble()???

    hi,
    i have used Double.parseDouble() method in my program. After i run that program in browser, it shows error "Double.parseDouble() method not found". Doesnt browser support Double.parseDouble()??? Can anybody tell me how to solve this error?? (i have also tried Float.parseFloat(),but same error occurs) Please help me.
    Thanks in advance,
    Kalpana.

    Newer non-Microsoft browsers such as Netscape 6 and Opera 5 support JDK 1.3. I think IE 5.1 for Mac OS X will use the JDK 1.3 installed on the computer, also. It's only older browsers and IE for Windows and Mac OS 9.1 and before that do not support JDK 1.3. Unfortunately, that's 90% of all browsers! :-(

  • Variants of Double.parseDouble

    I have an applet that runs perfectly on appletviewer but screws up when viewed through my web browser. It doesn't parse the string( number ) found in my textfield( input ). I did it like this: "x = Double.parseDouble( input.getText() );". what is the syntax that i should follow to conform with those that my browser could support? Probably an older one. My browser is IE 4 or 5... Thanks!

    Sun must have been struggling for a bit 'cos it wasn't until JDK1.2 that they introduced Double.parseDouble, even though Integer.parseInt has been there since the dawn of time itself.
    And since Microsoft stopped supported Java around JDK1.1.6 you'll probably find that your Applet is complaining that there's no such method (have a look in the Java Console in IE to see what it's got to say for itself).
    There are various things you could do:
    1) install the Java Plug-in to bring your JVM into this century
    2) see if DecimalFormat is supported by your runtime (can't find when it was introduced in the Javadocs - sorry)
    3) write your own simple double-parsing routine
    Personally I'd opt for 1. I'd be tempted to do option 2 as well but it's hardly necessary!
    Hope this helps.

  • Issue with Double.parseDouble

    ok i dono whats going on here im writing a console based bank management program and when converting a input srting from console.readline to Double.parseDouble it says the method parseDouble cannot be found, im using the latest jvm whats going on! help!

    my bad i ment latest jdk not thinking tonight! heres the error:
    D:\My Documents\Java\Bank Acount\AccountDriver.java:59: Method parseDouble(java.lang.String) not found in class java.lang.Double.
                             newAcc = Double.parseDouble (input);
                             ^
    1 error

  • Sequence.nextval doubles the returned value with Execute Statement (F9)

    There appears to be a quirk with sequences in Raptor.
    Has anyone noticed that depending on how you execute this sql (SELECT MYSEQ.NEXTVAL FROM DUAL;) the value returned is either the correct nextval or double what you expected?
    For example, MYSEQ is a simple sequence which increments by 1. If you Execute Statement (F9) then the value returned jumps by 2 instead of 1. If you Run Script (F5) then the value returns jumps by 1, as expected.
    If MYSEQ is changed to increment by 2. The when you Execute Statement (F9) then the value returned jumps by 4 instead of 2. If you Run Script (F5) then the value returns jumps by 2, as expected. No matter what you put for the increment by Execute Statement (F9) always doubles it.
    It always seems to be double. Executing the same scenario in TOAD always returns the correct value (i.e. properly increments).
    Is the query being executed multiple times with Execute Statement? Why is this happening?

    While there is no guarantee from Oracle that sequences produce sequential numbers, this is obviously a case where SQL Developer is running the select statement twice.
    The issue is that queries can actually change information, rather than just retrieve data from the database.
    The following package is a test case:
    create or replace package test_query is
    function get_next_count return number;
    end;
    create or replace package body test_query is
    cnt number := 0;
    function get_next_count return number is
    begin
    cnt := cnt + 1;
    return cnt;
    end;
    end;
    select test_query.get_next_count from dual;
    This query, which should return 1, 2, 3, 4, etc actually returns 2, 4, 6, 8, etc, because SQL Developer is running the select twice.

  • JDK 1.1.8 and Double.parseDouble

    I've downloaded JDK 1.1.8 from this web site.
    When I try to compile the program which includes converting input data into decimal number the compiler says that it can't find method parseDouble in the class java.lang.Double.
    I know that the source code is right, because I've tried to compile and run this program on another computer. Java applications on that computer are installed from Jbuilder CD.
    What's the problem with JDK 1.1.8?
    Thanx for help

    Depending on which version of JBuilder you have, it will install a JDK that is included with it.
    For example, JBuilder 6 has JDK 1.3.1, which includes the parsing function you are looking for.
    Why would you download 1.1.8 and not the latest version?
    Thanks,
    Haig

  • Textarea has double carriage returns

    I have some xml that looks similar to this
    <events>
    <event>
    <title> Event Title</title>
    <description>This is the event description
    When I have line breaks, like this
    the text area will show 2, everywhere
    that I only have one.
    </description>
    </event>
    </events>
    I have even tried removing the tabs, so that the only extra
    characters are CR LF , but I always see extra carriage returns in
    my textarea.
    Ayone know what is causing this ?

    * The TextArea control uses UNIX-style line endings, which
    means that text data containing Windows-style carriage-return
    line-feed (that is, \r\n) formatting for new lines contain extra
    line breaks. You can use String.replace() with a regular expression
    to convert the text to UNIX-style line endings, as the following
    example shows:
    private static const windowsCRLF:RegExp = /\r\n/gm;
    myTextString = myTextString.replace(windowsCRLF, "\n");
    http://www.adobe.com/support/documentation/en/flex/2/releasenotes_flex2_sdk.html

Maybe you are looking for