[not-a-bug] CDbl() and dividing process

Post Reply
Harley
Forum Regular
Posts: 312
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

[not-a-bug] CDbl() and dividing process

Post by Harley » Tue May 23, 2017 6:26 am

Hello everyone!
Maybe I missed something, but when I try to divide in CDbl() for example 1/4 I ever get 0!
But when I multiply in CDbl() 1*0.25, I get 0.25

About 2 years ago I already had this question, but didn't ask it.
Today, I suffered for two days and don't understand, why it's happens.

Need your answer. With best regards!

Nando
POL Developer
Posts: 260
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: CDbl() and dividing process

Post by Nando » Tue May 23, 2017 10:03 am

Do you mean CDbl(1/4)?

In this case, 1 and 4 are integers. An integer division tells you how many times the second number fits into the first as a whole. In this case, 4 never fits completely into 1, so you get zero.

The division you are used to uses real numbers. With those, you can represent 1.0/4.0 as 0.25, as they're not limited to whole numbers.

You need to convert at least one of the terms to a double if you want to have the real division.

Harley
Forum Regular
Posts: 312
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: CDbl() and dividing process

Post by Harley » Tue May 23, 2017 1:28 pm

Nando, thank you for ur answer!
I'll try and hope it'll help me and other people, who have discovered this one.

Post Reply