Results 1 to 2 of 2
  1. #1
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default ERROR : possible loss of precision

    Hi all,

    I tried to initialize a decimal value as shown below
    Java Code:
    float a = 30.9;
    It gives compiler error "possible loss of precision"
    But when I did typecasting as shown below it worked
    Java Code:
    float a = (float)30.9;
    Seems like it is interpreting 30.9 as double.

    In C and C++ it is okay to declare float variables as above.
    How is this different in Java? Could anyone please help.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    The literal 30.9 is indeed a double. To specify it as a float, add an F to the end:

    Java Code:
    float a = 30.9F

Similar Threads

  1. Possible Loss of Precision?
    By jwb4291 in forum New To Java
    Replies: 6
    Last Post: 12-02-2010, 04:28 AM
  2. Possible loss of precision
    By jankidudel in forum New To Java
    Replies: 2
    Last Post: 08-07-2010, 10:15 AM
  3. possible loss of precision?
    By gandalf5166 in forum New To Java
    Replies: 6
    Last Post: 04-13-2010, 08:21 PM
  4. help me- loss of precision error??
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 09-01-2008, 09:23 AM
  5. Connection Loss
    By CrazyShells Slam in forum New To Java
    Replies: 0
    Last Post: 05-15-2008, 02:56 PM

Posting Permissions

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