# Floating error  [SOLVED]

Questions about MultiCharts and user contributed studies.
stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

### Floating error

Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Best regards
Stefan

Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);

TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2041 times

### Re: Floating error

stefanols wrote:Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Best regards
Stefan

Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);

Please show us what/how you tried to correct the problem.

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

### Re: Floating error

Something like this:
value1=(C+2*StdDev(C,length)-average(C,length))*1.0000001;
Value2=(4*(StdDev(C,length)))*1.0000001;
Value3= ((value1)/(value2)*1.000001) *100;

TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2041 times

### Re: Floating error

What is zero times 1.0000001 ?
These users thanked the author TJ for the post:
stefanols

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

### Re: Floating error

you are right. How can i come around that then?

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

### Re: Floating error  [SOLVED]

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

### Re: Floating error

Thanks!

ABC
Posts: 625
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 354 times
Contact:

### Re: Floating error

stefanols wrote:I should add 0.000001 then?

stefanols,

what if Value2 = -0.000001?

I would suggest to check if the denominator of a division is different than 0 (for every division that you perform within a code). If it is, do the division otherwise you can do something else (optional).

For example:

Code: Select all

if denominator <> 0 then
result = numerator / denominator
else
result = 0 ;

Regards,

ABC
These users thanked the author ABC for the post:
stefanols