473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sqrt operation for decimal

I've changed from double to decimal calculations but I can't find a math
library for decimal (mainly for sqrt),
Thanks Maor
Nov 15 '05 #1
2 7083
Since Math.Sqrt only uses double you will have to cast it to and from
double.

decimal d = 0.0000000000000000000000000002m;
decimal e = (decimal)Math.Sqrt((double)d);

// e == 0,000000000000014142135623731

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode and Nostalgia enabled
Nov 15 '05 #2
Maor Mishkin wrote:
I've changed from double to decimal calculations but I can't find a math
library for decimal (mainly for sqrt),
Thanks Maor


Hi Maor,

I'm affraid that Math.Sqrt is only choice...
and it works with double numbers only.
You can write your own DecimalSqrt function:

public static decimal Sqrt(decimal val) {
return new Decimal(Math.Sqrt((double) val));
}

Regards

Marcin
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pauldepstein | last post by:
I am writing a program which will use the ceiling and floor of square roots. If a positive integer is an exact square (and is not overly huge), does sqrt return an integer-valued real? Or...
11
by: Marcin | last post by:
Hello! How I can make SQRT(2) with 20 digits precision (after float point)?
2
by: Maor Mishkin | last post by:
I have a problem with divide operation, the example is: double a =10.0; double b =220.0; double divAns = a/b; the calculation true result is 0.04545454545454545 but for some resone the...
1
by: David Dvali | last post by:
How can I use Math.Sqrt() with Decimal data?
12
by: Thomas Zhu | last post by:
hello all, n is an 32bit-integer, how to calculate sqrt(n) I know high(n) is the the value, but how to use bit operation to implement this function. thanks in advance. yours Yin
14
by: peng.xiaoyu | last post by:
hello everyone, why this c code can be compiled and linked without -lm? #include<math.h> #include<stdio.h> int main() { printf("%f\n",sqrt(2.0)); return 0;
2
by: backwards15 | last post by:
Having a bit of trouble with rounding and math.sqrt. I have below a small function that generates a 4 diget code from the square root of the date. Public Function Generate() As String Dim n...
17
by: pyramid | last post by:
Hello I am working on one of my lab for this week, which calculates the approximate value of pi. Listed below is the actual problem, which I am posting here, so that you can see the different...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.