How to parse signed zero?

后端 未结 3 1186
北海茫月
北海茫月 2021-01-07 19:37

Is it possible to parse signed zero? I tried several approaches but no one gives the proper result:

float test1 = Convert.ToSingle(\"-0.0\");
float test2 = f         


        
3条回答
  •  长情又很酷
    2021-01-07 20:01

    You can try this:

    string target = "-0.0";  
    decimal result= (decimal.Parse(target,
                     System.Globalization.NumberStyles.AllowParentheses |
                     System.Globalization.NumberStyles.AllowLeadingWhite |
                     System.Globalization.NumberStyles.AllowTrailingWhite |
                     System.Globalization.NumberStyles.AllowThousands |
                     System.Globalization.NumberStyles.AllowDecimalPoint |
                     System.Globalization.NumberStyles.AllowLeadingSign));
    

提交回复
热议问题