Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Convert Int to Doubel value without exponents and decimal value.

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Convert Int to Doubel value without exponents and decimal value.

    Hi,

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

    integer intNum = 285292746;
    double dNumber = Double.parseDouble(Integer.ToString(intNum));

    It returns double number with exponential and decimal. Type return should be Double.
     dNumber = 2.85292746E8


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

    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();
     
    DecimalFormat formatter = new DecimalFormat("#.000000");
    System.out.println(formatter.format(dd));
    }
    }

    Eventually i need to pass this double value to

    JAXBElement<Double> fileId = _of.CreateFileId(Double);

    Please give me some tips or ideas. How should I handle it.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    we see that Math.floor(double a) turns the provided double into the equivalent double with no decimal component..

    Math.floor(10.99999) returns 10.0 (as a double)

    which you can then convert to an integer simply by casting:

    int myInt = (int) Math.floor(10.99999);
    //myInt is equal to 10

    similarly, the round() function can be looked up.. round rounds 10.0 to 10.49999... down to 10.0, and 10.5 to 10.999999... up to 11.0

    there is another related operation, ceiling, that rounds any double up to the next whole double with no decimal component, so 10.49999, becomes 11.0
    It is symantically equivalent to :
    Math.floor(double a +1)

Similar Threads

  1. Converting Hex to Decimal
    By r2ro_serolf in forum Java Theory & Questions
    Replies: 10
    Last Post: September 4th, 2011, 04:29 PM
  2. print hex decimal value
    By ran830421 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 25th, 2009, 07:23 PM
  3. decimal and hexdecimal
    By ran830421 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 21st, 2009, 02:58 AM
  4. decimal to hex
    By rsala004 in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 3rd, 2009, 02:16 AM
  5. [SOLVED] How to use decimal place when formatting an output?
    By napenthia in forum Java Theory & Questions
    Replies: 2
    Last Post: April 27th, 2009, 03:17 AM