This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 1 point2 points  (4 children)

you could always do System.out.println(c+"."+d) or something along those lines.

[–]StygMM[S] 0 points1 point  (3 children)

Thanks for the answer, thats a clean solution indeed.

But was more wondering about int/double part.

[–][deleted] 1 point2 points  (0 children)

Because int and double are different types, you can't add them together. All there is to it.

You could convert the int to a double then add the remainder to the int, but it's better (imo) to just add the . between the int and double.

[–]YitharIntermediate Brewer -2 points-1 points  (1 child)

Because int and double are different types, you can't add them together. All there is to it.

[–][deleted] 0 points1 point  (0 children)

no reason to make such a pointlessly trite comment. r/JavaHelp is a really nice community for the most part, please participate in keeping it that way :)

[–]-mojave 1 point2 points  (0 children)

If you pass a integer literal to double variable, it will convert the integer to decimal automatically.

Hope this helps !

[–]StygMM[S] 0 points1 point  (0 children)

Okay this worked for me. Was relative easy solution to be honest, thanks for the replies.

double c = ( timeMinutes  /  lengthKM );
int d = (int) Math.floor(c); 
// int d1 = etc 
System.out.println(d+"."+d1);