How to calculate Sqrt (square root)?
Author: Harapa
Creation Date: 8/20/2019 4:14 PM
profile picture

Harapa

#1
How can I get Sqrt of n0 for int n2 programmatically?

CODE:
Please log in to see this code.



profile picture

Eugene

#2
Hmm, you're not looking for easy ways. How about Math.Sqrt which is built into .NET?

P.S. For DataSeries there's Sqrt indicator in Community Indicators:

Sqrt function
Sqrt is a type but is being using like a variable
profile picture

Harapa

#3
Sqrt indicator needs a data series.

Math.Sqrt works

CODE:
Please log in to see this code.


but

How do I convert output of Math.Sqrt to a integer (as a whole number is needed in the next step(s))?
profile picture

Eugene

#4
You'll be surprised but .NET framework would be pretty pale if it couldn't round a double to integer out of the box. Simply use a search engine like this:

c# double to integer

And the very first hit shows you two approaches - using Math.Round (or its peers) or Convert.ToInt*:

convert double to int
profile picture

Harapa

#5
This works
CODE:
Please log in to see this code.


Thanks for your help.
profile picture

Eugene

#6
You're welcome.
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).