本文介绍了如何将负字符串转换为十进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将像-23.27"
这样的负字符串转换为小数点值,有时问题是我在括号内得到了像(23.27)"这样的负值.
Im trying to convert a negative string like
"-23.27"
to a decimal point value, And the problem is sometimes im getting negative values inside parenthesis like "(23.27)"
.
我已经编写了控制括号的代码,并以负格式获取小数点值,但是当同一代码运行
-23.27"
时,它返回的输入字符串不正确格式错误.这是我的代码.任何帮助将不胜感激.
I have written the code to control parenthesis And get the decimal point value in negative format, but when the same code is running with
"-23.27"
it returns a Input string was not in a correct format Error. This is my code. Any help would be appreciated.
decimal ValueN = (decimal.Parse("-23.27",
System.Globalization.NumberStyles.AllowParentheses |
System.Globalization.NumberStyles.AllowLeadingWhite |
System.Globalization.NumberStyles.AllowTrailingWhite |
System.Globalization.NumberStyles.AllowThousands));
推荐答案
您缺少
AllowLeadingSign
标志
decimal ValueN= (decimal.Parse("-23.27",
System.Globalization.NumberStyles.AllowParentheses |
System.Globalization.NumberStyles.AllowLeadingWhite |
System.Globalization.NumberStyles.AllowTrailingWhite |
System.Globalization.NumberStyles.AllowThousands |
System.Globalization.NumberStyles.AllowDecimalPoint |
System.Globalization.NumberStyles.AllowLeadingSign));
这篇关于如何将负字符串转换为十进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!