Results 1 to 8 of 8
  1. #1
    jabong is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: data typeconversion

    What did you try, and what was the result?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    prmdgurav is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: data typeconversion

    you can convert datatype using typecasting

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: data typeconversion

    Here's an example:
    Java Code:
    byte b = 42;
    Integer i = new Integer(String.valueOf(b));
    Double d = Math.floor(Double.parseDouble(String.valueOf(i)));
    int result = d.intValue();
    System.out.println("result = " + result);

  5. #5
    pratapsingh is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: data typeconversion

    Byte b = new Byte(rno[0]);
    int i = b.intValue();

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: data typeconversion

    There is no need to go via the String domain, nor are the primitive wrappers needed, not even an explicit simple type cast is needed; converting from a byte type to an int type is implicit because it is a widening conversion.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: data typeconversion

    Quote Originally Posted by JosAH View Post
    There is no need to go via the String domain, nor are the primitive wrappers needed, not even an explicit simple type cast is needed; converting from a byte type to an int type is implicit because it is a widening conversion.

    kind regards,

    Jos
    I know, I was just being teasy because of the way the question was asked.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: data typeconversion

    Also, did you want to preserve the sign bit or not? Widening assignments or casts extend the sign bit. So
    if byte b = -9 and you assign it to an int, you will still have -9, not 247.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 11
    Last Post: 09-21-2012, 09:33 AM
  2. Getting problem inserting data in data base
    By anupama in forum New To Java
    Replies: 4
    Last Post: 12-15-2010, 10:03 PM
  3. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 04:10 PM
  4. Replies: 0
    Last Post: 10-31-2008, 02:13 PM
  5. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:52 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
  •