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?

*Practice only makes habit, only perfect practice makes perfect.*—every music teacher ever

*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.*—every music teacher ever

*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.*—every music teacher ever

*Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

- 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

It is worth to point out, that OP didn't get 0.0 with his initial code snippet, but rather 0.

- 2

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".

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.