是否有可能解析有符号的零?我尝试了几种方法,但没有人给出正确的结果:
float test1 = Convert.ToSingle("-0.0");
float test2 = float.Parse("-0.0");
float test3;
float.TryParse("-0.0", out test3);
Run Code Online (Sandbox Code Playgroud)
如果我使用直接初始化的值就可以了:
float test4 = -0.0f;
Run Code Online (Sandbox Code Playgroud)
所以问题似乎在于c#的解析过程.我希望有人可以判断是否有一些选项或解决方法.
只能通过转换为二进制来看到差异:
var bin= BitConverter.GetBytes(test4);
Run Code Online (Sandbox Code Playgroud)