Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert C# code to Java - Floating Point Arithmetic

Andy DufresneJan 1 2011 — edited Jan 9 2011
Convert C# code to Java - Floating Point Arithmetic

Hello,
I need to write a C# equivalent code in java. The C# code includes functions performing mathematical calculations. The result of these functions should exactly match with the C# counterpart (especially the precision). Below is one of the functions which needs a java equivalent

public static string squareroot(string n1)
{
if ((n1 == null) || (System.Convert.ToDouble(n1) < 0) )
{ return null; }
else {
return System.Convert.ToDecimal(Math.Sqrt(System.Convert.ToDouble(n1))).ToString();
}
}

C# includes two floating point data types - float(32 bit) and double(64 bit). It also includes a more precise floating point data type called decimal (128 bit). Both float and double are said to follow the IEEE 754 floating point standard, but the precision digits differ. C# double has 15-16 precision digits while the java equivalent has 53, right? (referring the IEEE standard).

Does anyone have any idea on what java equivalent data types/libraries should be used such that the outcomes match with C# double and decimal?

Thanks in advance & a happy new year
This post has been answered by sabre150 on Jan 3 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2011
Added on Jan 1 2011
13 comments
1,677 views