how to convert a String value to double value after formatting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shiniskumar
    New Member
    • Feb 2007
    • 58

    how to convert a String value to double value after formatting

    Ive got a double variable dTotal =5.037717235E7
    i formatted it using
    deciFormat.form at(dTotal) and got the String value of dTotal=50377172 .35

    now i have to pass this value as an argument to a function

    convert(double num);


    how can i convert the string value 50377172.35 to double?

    Please help
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shiniskumar
    Ive got a double variable dTotal =5.037717235E7
    i formatted it using
    deciFormat.form at(dTotal) and got the String value of dTotal=50377172 .35

    now i have to pass this value as an argument to a function

    convert(double num);


    how can i convert the string value 50377172.35 to double?

    Please help
    Code:
     Double.parseDouble(dTotal);

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by shiniskumar
      Ive got a double variable dTotal =5.037717235E7
      i formatted it using
      deciFormat.form at(dTotal) and got the String value of dTotal=50377172 .35

      now i have to pass this value as an argument to a function

      convert(double num);


      how can i convert the string value 50377172.35 to double?

      Please help
      Code:
       Double.parseDouble(dTotal);

      Comment

      • shiniskumar
        New Member
        • Feb 2007
        • 58

        #4
        Originally posted by r035198x
        Code:
         Double.parseDouble(dTotal);
        Double.parseDou ble(deciFormat. format(dTotal)) gives me 5.037717235E7

        i need to get 50377172.35 as argument

        Comment

        • shiniskumar
          New Member
          • Feb 2007
          • 58

          #5
          Originally posted by shiniskumar
          Double.parseDou ble(deciFormat. format(dTotal)) gives me 5.037717235E7

          i need to get 50377172.35 as argument
          Please help

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by shiniskumar
            Double.parseDou ble(deciFormat. format(dTotal)) gives me 5.037717235E7

            i need to get 50377172.35 as argument
            But they are equivalent.

            If the function is expecting a double then pass it the value like 5.037717235E7 it doesn't matter. Why do you want to make it 50377172.35? first.

            Comment

            • shiniskumar
              New Member
              • Feb 2007
              • 58

              #7
              Originally posted by r035198x
              But they are equivalent.

              If the function is expecting a double then pass it the value like 5.037717235E7 it doesn't matter. Why do you want to make it 50377172.35? first.
              I need to split this number into two integers so that i can print the total in words

              ie the number b4 "." will be in rupees and the number after "." will be paise part.

              Thus i get error when something with E7 comes in integer part

              Comment

              • shiniskumar
                New Member
                • Feb 2007
                • 58

                #8
                help please

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by shiniskumar
                  I need to split this number into two integers so that i can print the total in words

                  ie the number b4 "." will be in rupees and the number after "." will be paise part.

                  Thus i get error when something with E7 comes in integer part
                  Do not pass it as double then. Parse it a String
                  You can then use
                  Code:
                   String s= "50377172.35"; 
                  String[] values = s.split("\\.");
                  Which gives you an array of the value split on the .

                  Comment

                  Working...