解析率翻番 [英] Parse percentage to double

查看:113
本文介绍了解析率翻番的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更好的方法来解析率翻番这样吗?

 昏暗的缓冲区的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.

这篇关于解析率翻番的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆