Unexpected result of Math.Round
Author: Starburst
Creation Date: 8/20/2013 6:40 PM
profile picture

Starburst

#1
Why am I having issues with this line? VarP = (int)Math.Round((VarNumBars / 5), 0 );
Thank you
CODE:
Please log in to see this code.
profile picture

LenMoz

#2
Dividing integers truncates.

Try this little test...
CODE:
Please log in to see this code.

I think you'll be surprised,
profile picture

Eugene

#3
1. FAQ: I'm trying to divide two numbers and the result is zero.

2. Next, another issue is incomplete initialization:
CODE:
Please log in to see this code.

Could be:
CODE:
Please log in to see this code.


3. Big performance hit is coming from this line:
CODE:
Please log in to see this code.

Since VarP never changes, this should be defined as a DataSeries before the loop.

4. Finally, VarP is 0 so your script does nothing.

The complete script that doesn't work because of NumBars:

CODE:
Please log in to see this code.

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).