Convert C# code to Java - Floating Point Arithmetic
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