0

How to parse in C# string "-0" to long value -9223372036854775808 (hex: 0x8000000000000000)?

The following code shows that the values are not equal.

double negativeZero = -0.0;
long negativeZeroLong = BitConverter.DoubleToInt64Bits(negativeZero);  // 0x8000000000000000
long parsedNegativeZeroLong = BitConverter.DoubleToInt64Bits(System.Double.Parse("-0.0", System.Globalization.NumberStyles.Float)); //0
Console.WriteLine("{0} != {1}", negativeZeroLong.ToString("X"), parsedNegativeZeroLong.ToString("X")); //8000000000000000 != 0
TomaC
  • 89
  • 6
  • This makes no sense I'm afraid. There's no such thing as negative zero. – DavidG May 08 '18 at 12:53
  • 3
    @DavidG Actually there is https://stackoverflow.com/questions/3139538/is-minus-zero-0-equivalent-to-zero-0-in-c-sharp – juharr May 08 '18 at 12:53
  • This might help you: https://stackoverflow.com/questions/24299692/why-is-a-round-trip-conversion-via-a-string-not-safe-for-a-double – Raviprakash May 08 '18 at 12:53

0 Answers0