有没有更好的方法来解析率翻番这样吗?
昏暗的缓冲区的String =50.00%
昏暗的值作为双= Double.Parse(Buffer.Replace(%,),NumberStyles.Any,CultureInfo.InvariantCulture)/ 100
解决方案
你正在做的方式似乎对我好。
的唯一一点,我会小心的是,你的程序是假设InvariantCulture的。确保这其实是你的意思。例如,它可能会更好地使用机器的默认文化,如果你的字符串是来自用户的输入,而不是一个固定的定义明确的协议。
Is there a better way to parse percentage to double like this?
Dim Buffer As String = "50.00%"
Dim Value As Double = Double.Parse(Buffer.Replace("%",""), NumberStyles.Any, CultureInfo.InvariantCulture) / 100
解决方案
The way you are doing it seems good to me.
The only point I would be careful about is that your program is assuming InvariantCulture. Make sure this is actually what you mean. For example it might be better to use the machine's default culture if your string comes from user input rather than a fixed well-defined protocol.