Help, how to extract the integer part
Solved
Thinathenet
Posted messages
23
Status
Membre
-
Thinathenet Posted messages 23 Status Membre -
Thinathenet Posted messages 23 Status Membre -
Hello,
How can I extract the integer part of a real number using Java, and thank youuu :) !!!
How can I extract the integer part of a real number using Java, and thank youuu :) !!!
2 réponses
Hello,
The primitive that represents real numbers is "double".
So, to extract the integer "int" from this real number, just do as in this example:
The result:
Good luck
Being normal is boring... being geek is interesting
The primitive that represents real numbers is "double".
So, to extract the integer "int" from this real number, just do as in this example:
double d = -12.91; System.out.println("d= " + d); int i = (int) d; System.out.println("i= " + i); The result:
d= -12.91 i= -12
Good luck
Being normal is boring... being geek is interesting
So the part is (-12) and the integer part with rounding is (-13).
And for a former specialist in Mathematics, it was serious and cool to forget the fundamentals.
Since it's the first time I'm programming with Java and on top of that for my final thesis, it's a bit difficult for me!