无法将'string'类型转换为'float'

Mah*_*eem 2 c# asp.net

我收到此错误:

Cannot convert type 'string' to 'float'
Run Code Online (Sandbox Code Playgroud)

在以下代码行:

float x=(float )(TextBox_item_price.Text);
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

Ulu*_*rov 5

你需要这样做

float x = float.Parse(TextBox_item_price.Text);
Run Code Online (Sandbox Code Playgroud)