1. Member
Join Date
Jul 2013
Posts
12
Rep Power
0

## what is (int)?

hi!

int []days=new int [10];

days[i]=(int) ((interestEarn[i])/(principle[i]*rate[i]/100*1/365.0));

is there any way to make the (int) go away without changing days to double?

2. Member
Join Date
Jan 2013
Location
Kolkata,India
Posts
90
Rep Power
0

## Re: what is (int)?

It is called type casting mate.It converts / forces the jvm to convert data type maybe float,double to int.
is there any way to make the (int) go away without changing days to double?
Actually the days are in int form.See the array is in int form so the days are also in int form else there would be an error mate.If your 'interestEarn' ,'principle' are in int form the you cam remove the (int)
Last edited by harshit shah; 07-28-2013 at 04:46 PM.

3. ## Re: what is (int)?

That (int) thing is just a cast; it casts a double type value to an int type value. The expression value is of type double because you did a division by a double value (365.0)

kind regards,

Jos

4. Member
Join Date
Jul 2013
Posts
12
Rep Power
0

## Re: what is (int)?

hi jos...

so you saying just delete of the .0??

kai

5. Member
Join Date
Jul 2013
Posts
12
Rep Power
0

## Re: what is (int)?

hi harshit shah

ummm...but i have to use both interestEarn and principle as double....
coz actually it is actually much longer program =)

6. Member
Join Date
Jan 2013
Location
Kolkata,India
Posts
90
Rep Power
0

## Re: what is (int)?

Originally Posted by kai
hi harshit shah

ummm...but i have to use both interestEarn and principle as double....
coz actually it is actually much longer program =)
if both are in double the type casting is the only way by which you can make the days in int form else the jvm would automatically convert days to double.Moreover there would a loss of precision error.

7. Member
Join Date
Jan 2013
Location
Kolkata,India
Posts
90
Rep Power
0

## Re: what is (int)?

Originally Posted by kai
hi jos...

so you saying just delete of the .0??

kai
Even if you delete the .0 the other two 'interestEarn' ,'principle' are in double form so that would lead the days to go in point form again.

8. Member
Join Date
Jul 2013
Posts
12
Rep Power
0

## Re: what is (int)?

Originally Posted by harshit shah
if both are in double the type casting is the only way by which you can make the days in int form else the jvm would automatically convert days to double.Moreover there would a loss of precision error.

So there is no other way.. but "have" to use the cast?

9. ## Re: what is (int)?

Originally Posted by kai
So there is no other way.. but "have" to use the cast?
Yep, you have to because a double (8 bytes) doesn't fit in an int variable (4 bytes); but what is so scary about a simple cast?

kind regards,

Jos

10. Member
Join Date
Jul 2013
Posts
12
Rep Power
0

## Re: what is (int)?

Originally Posted by JosAH
Yep, you have to because a double (8 bytes) doesn't fit in an int variable (4 bytes); but what is so scary about a simple cast?

kind regards,

Jos

haha i dont know... i heard my lecturer said there is a way to not use (int)...maybe it was not for me

11. Member
Join Date
Jul 2013
Posts
2
Rep Power
0

## Re: what is (int)?

Originally Posted by kai
haha i dont know... i heard my lecturer said there is a way to not use (int)...maybe it was not for me
The only problem with the type casting to int is your number will be truncated. That is to say only the the value to the left of the decimal point will remain. for example (int) 6.9 => 6.

Your teacher may have wanted you to round your answer in which case you will need to do (int) Math.round(...). But I am just speculating what your teacher wants.

#### Posting Permissions

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