Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default Pleases help - Convert Int to Doubel value without exponents and decimal value.

    I want to convert int value to double value without any exponents and decimal values.
    I have following int number i need to convert this to double. Because server side code is expecting data type in double.

    Java Code:
    integer intNum = 285292746;
    double dNumber = Double.parseDouble(Integer.ToString(intNum));
    When i parse as shown above It returns double number with exponential and decimal. Type return should be Double.

    Java Code:
     dNumber = 2.85292746E8 //Returned
    I expect double return value to be 285292746 plain with no Exponential values or decimal in middle.

    I need to pass double value to server code but in plain format like 285292746 or it can accept 285292746.0000000 but no E /Exponential value and decimal values in the middle.

    I m new to Java. I know if do type cast as double it give me 285292746.00000000 which will work for my case but in java after typing casting/coverting int to Double it gives exponential value and decimal at the begininng. Final return value should be double.

    Java Code:
    public class prog2
    {
    public static void main(String args[])
    {
     
    int  intNum = 285292746;
     
    double dNumber = Double.parseDouble(Integer.ToString(intNum));
     
    String str = Double.toString(dNumber);
    Double d = new Double(str);
    double dd = d.doubleValue(); //Still returned dd value as 2.85292746E8
     
    DecimalFormat formatter = new DecimalFormat("#.000000");
    System.out.println(formatter.format(dd));
    }
    }
    Eventually i need to pass this double value to

    Java Code:
    JAXBElement<Double> fileId = _of.CreateFileId(Double);
    I looked into floor method and round method too. The problem is i dont want to round value. I need same exact values as double.. Because Double value is database unique ID.

    I want to pass exact same value. Because server accepts Double value. Datatype is defined in xsd:double type in WSDL file. I am going to pass this double value from client.
    Java Code:
    dNumber = 2.85292746E8 //
    double val = 285292746 is the one I need to get.
    Please give me some tips or ideas. How should I handle it. Even Is it possible?
    Last edited by project25_java; 11-02-2011 at 02:36 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: Pleases help - Convert Int to Doubel value without exponents and decimal value.

    There's a difference between what the double's value is and how it's displayed. Why does your server care about how it's displayed? You might want to look into the DecimalFormat class.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,040
    Rep Power
    10

    Default Re: Pleases help - Convert Int to Doubel value without exponents and decimal value.

    Like I said, the value of the double and the way it is displayed are two completely different things. That scientific notation is not a part of the actual value, it's simply how it's being displayed. So of course the DecimalFormat class methods won't return a double, because the value alone has nothing to do with the format of the output. I still don't understand why your server cares about how the value is displayed, but what I'm suggesting you do is pass it as a String, then do the conversion on the server side. My guess is that something else is the problem, but this is one way to go about eliminating possibilities.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. convert to decimal
    By rjagan in forum New To Java
    Replies: 6
    Last Post: 06-21-2011, 02:34 PM
  2. Convert Decimal To Binary
    By aspire007 in forum New To Java
    Replies: 8
    Last Post: 08-06-2010, 08:32 AM
  3. Replies: 4
    Last Post: 10-26-2009, 11:17 PM
  4. Convert binary into decimal
    By WarmRegards in forum New To Java
    Replies: 8
    Last Post: 10-18-2009, 03:32 PM
  5. Convert decimal to binary..pls help..newbie here
    By mephisto772 in forum New To Java
    Replies: 5
    Last Post: 02-12-2009, 09:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •