将字符串转换为浮点数据类型 [英] Converting a string to a float data type
本文介绍了将字符串转换为浮点数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将文本框(货币)的内容转换为数据类型float。
我可以转换为单行吗?
I need to convert the contents of a Textbox (which is currency) to a datatype float. Would I convert to single?
txtPurchItemCorrectPrice.Text.Trim();
txtPurchItemCorrectPrice.Text.Trim();
推荐答案
如果您要处理货币,那么我会在 double
至少,如果不是十进制
。那就是说你想要:
If you're dealing with currency then I would use double
at the very least, if not decimal
. That said you want:
double value = double.Parse(txtPurchItemCorrectPrice.Text.Trim());
如果不确定是否为数字:
If you're not sure whether it will be a number or not:
double value;
bool isOK = double.TryParse(txtPurchItemCorrectPrice.Text.Trim(), out value);
这篇关于将字符串转换为浮点数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文