Convert.ToInt32(float) fails when trying to convert float to Int32

前端 未结 4 960
情话喂你
情话喂你 2021-01-18 11:38

No exception is thrown, function just halts at this statement:

int productQuantity = Convert.ToInt32(\"1.00\");

and returns.

What

4条回答
  •  醉梦人生
    2021-01-18 12:12

    You need to convert it to a double first, and then convert to Int32.

    int productQuantity = Convert.ToInt32(double.Parse("1.00"));
    

提交回复
热议问题