Hey, I have a little question about division of two numbers.
For example, if a user enter these two numbers : 30 and 40
How can I make my programm show the whole decimals and not only the 0 ?
Because this is the kind of result I get :
How can you change this ? Thank you !
That is integer division. The reason is that 30 and 40 are integer literals. If you want to do a floating-point divide, at least one of the values must be a floating-point type.
Any of these should work:
30.0 / 40.0
30 / 40.0
30.0 / 40
However, if the user enters these values, then the variable which receives the input must be of a suitable type (double or float) instead of int.
Last edited on
you can also do
30f / 40
30 / 40f
30f / 40f