Results 1 to 3 of 3
  1. #1
    Josep_16's Avatar
    Josep_16 is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Possible loss of precision (short)

    Hello, I've got a short variable which starts at 0, (I assign it at init() as "t = 0"); then, I add to it 0.01 (with "t = t + 0.01"). For some reason, when I compile, it gives me the error "possible loss of precision, found: double, required:short". Where's the error? Thanks!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Did you try executing it and printing out the value of t after adding 0.01 to it?
    The compiler generates code to do floating point arithmetic for the expression: t + 0.01
    Then assigns the results to an int. What is the value of the expression?
    What will be the value of the int? Will you lose any data?
    The compiler is warning you about what happens.

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Rep Power


    Hmmm, I think the compiler just told what you need to do and what it just saw.

    Java Code:
     possible loss of precision, found: double, required:short
    It found a double, but wanted a short. Sooo, change, whichever one is getting the error (maybe it is 't'), your variable to a short.

Similar Threads

  1. ERROR : possible loss of precision
    By subith86 in forum New To Java
    Replies: 1
    Last Post: 01-19-2011, 06:17 PM
  2. Possible Loss of Precision?
    By jwb4291 in forum New To Java
    Replies: 6
    Last Post: 12-02-2010, 05:28 AM
  3. Possible loss of precision
    By jankidudel in forum New To Java
    Replies: 2
    Last Post: 08-07-2010, 10:15 AM
  4. possible loss of precision?
    By gandalf5166 in forum New To Java
    Replies: 6
    Last Post: 04-13-2010, 08:21 PM
  5. help me- loss of precision error??
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 09-01-2008, 09:23 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