1. Precision of retrieved data
2. serializable double with precision
When I serialise an object I would like to have a double precision in the "double" type : My code: private double _price = 100; public double Price ( get (return;) set (_price = value;) } Serialize : <price> 100 </ price> And i want: <price> 100.00 </ price> How do ? thanks
3. Specify precision of decimal? - CSharp/C#
Consider the following program:
class Program
{
static void Main(string[] args)
{
double z = 2.3;
double x = 2.3*100;
double y = 230.0;
short s = (short)x;
Console.WriteLine(z);
Console.WriteLine(y.ToString("G17"));
Console.WriteLine(x.ToString("G17"));
Console.WriteLine(s);
}
}
Why is the output:
2.3
230
229.99999999999997
229
Press any key to continue . . .
The computer can store 230 exactly.
5. ADO.Net - Field size and precision - CSharp/C#
6. C# double value precision is 42bit?
With the test I've made on my WinXP/VS2005/C#2.0,
I get a precision of 42bit. Is this specified in C# or dependent on what?
double dLeft = 2183.23 - 695.37;
double dRight = 1487.86;
double dFraction = Math.Pow(2, -42);
if (Math.Abs(dLeft - dRight) == dFraction) {
System.Console.WriteLine("Success");
}
// Output: Success
7. More precision and with highest range value type - CSharp/C#
8. inconsistent double precision math
I'm seeing a very strange behavior with double precision subtraction.
I'm using csUnit for testing. If I run the test by itself, the test
passes. When I run the batch of tests, the test fails. Here's the
test:
[Test]
public void GetAcuteAngleDifference_PI()
{
double a = 0;
double b = Math.PI;
Assert.Equals( b, Euclid.GetAcuteAngleDifference(a, b));
}
/// <summary>
/// Get the smallest acute difference between 2 angles. A positive
result
/// shows that b is clockwise of a, while a negative shows that b is
/// counter clockwise of a.
/// </summary>
/// <param name="a">angle in radians</param>
/// <param name="b">angle in radians</param>
/// <returns>smallest accute angle in radians</returns>
public static double GetAcuteAngleDifference(double a, double b)
{
a = SnapAngle(a); //place the angle between 0 and 2 Pi
b = SnapAngle(b);
if (a == b) return 0;
double result = b-a; //////////This line gives me grief.///////
double absResult = Math.Abs(result);
double direction = absResult / result;
if (absResult > Math.PI) //the acute angle is the opposite
direction
result = direction * (absResult - (2 * Math.PI));
return result;
}
The test is looking for the smallest acute angle between 0 and Pi. The
expected result is Pi.
Like I said, if I run the test by iteself, it passes. The 'result'
after the (b-a) subtraction is essentially (Math.PI - 0) and the result
the same as Math.PI = 3.141592 6535897931. However, the batch run
shows 'result' variable is slightly bigger at 3.141592 7410125732.
Has anyone else experienced this behavior? What can I do to correct it
or work around it?
BTW, the test is running a Debug build on a 2.8 Ghz Pentium 4.
Thanks!
Marshall