Changing Data types again....

Hi

Having probs changing data from INT to Double. I keep getting the 'possible loss of precision' error, though I can do it the other way it seems.

Duration is the INT field -

Duration = (double) Duration - Credit

It wont compile

If anyone could give me some info id appreciate it

[353 byte] By [Sacreda] at [2007-10-2 3:15:06]
# 1
> Duration = (double) Duration - CreditCan you tell me the types of these references
WirajRa at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 2
Credit is a double, duration is an int, I'm trying to get the two to work together to no avail
Sacreda at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 3

Then you are trying to assign double to int so you will have a loss of precision like if the result is 12.875 your int variable will only hold 12 that what the compiler is trying to tell you . You need to explicitly cast to avoid this

Duration = (int) (Duration - Credit);

WirajRa at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 4
But thats it I dont want to lose precision I want to cast the INT into a double if possible, so it would be double duration and double credit being calculated.
Sacreda at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 5

> But thats it I dont want to lose precision I want to

> cast the INT into a double if possible, so it would

> be double duration and double credit being calculated.Then you shouldn抰 assign the value back to an int variable, there isn抰 any way around it . You will have to rethink your design, why did you declare Duration as an int

WirajRa at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 6
Its in seconds, I was told to do it this way...I'm confusing myself and I guess your right
Sacreda at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...
# 7
So if you are not interested in milliseconds probably rounding up to int is a good idea. It抯 a design decision you have to make
WirajRa at 2007-7-15 21:42:18 > top of Java-index,Java Essentials,New To Java...