Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
Junilu Lacar wrote:Numeric literals that do not have a decimal point are treated as int values thus the expression 2 / 100 divides two int values. Integer division will produce an integer value and in this case it will be 0. That is the value that gets assigned to your double result variable.
Thank Junilu for the quick answer!
So the correct literals to use must be double as well:
And it actually gives the expected 0.02 result.
Thanks again!
dan
Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
 X 2
Daniele Barell wrote:Hi all,
This is my first post in the ranch and hope it's the right place to do it.
Here's the strange behavior I would ask for:
the output expected is 0.02
the real output is 0.0!
Why is that?
Your code can rewrite like this:
division between 2 to 100 (2/100) equals to 0 because the result of that division is an integer.
After division, casting the result of division is performed (double(0))
And the result is : 0.0
Dave Tolls wrote:
Liutauras Vilda wrote:
It is worth to point out, that OP didn't get 0.0 with his initial code snippet, but rather 0.
Might depend on your locale.
en_GB gives "0.0".
Oh, my mistake, I didn't see the result was assigned to result which is of type double.
In my mind I thought for some reason about the case:
Thanks for correcting me.
Today you are you, that is turer than true. There is no one alive who is youer than you!  Seuss. Tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
