double.TryParse(要转换的数字字符串, out 转换后的数字)返回值是表示转换是否成功,所以你应该声明一个doulbe变量,如声明double变量num,那么你的这句代码book.Price = double.TryParse(book_price, out 0.00)改成bool b=double.TryParse(book_price, out num),book.Price =num
double.TryParse(要转换的数字字符串, out 转换后的数字)返回值是表示转换是否成功,所以你应该声明一个doulbe变量,如声明double变量num,那么你的这句代码book.Price = double.TryParse(book_price, out 0.00)改成bool b=double.TryParse(book_price, out num),book.Price =num
猴岛:2b青年欢乐多° 为你解答
明显就是转换那里有问题嘛:
1、将传入的字符串转换为等效的浮点数做为书籍的价格?
2、这个应该是用decimal比较好吧?
3、检查你传入的参数是否能够正确转换;
4、检查你的book.Price是不是double类型;
5、试试这样:book.Price=Convert.ToDouble(book_price);
class Program
{
static void Main(string[] args)
{
string value = "3.1415926";
double d = 0;
Double.TryParse(value, out d);
Console.WriteLine(d);
Console.Read();
}
}
这个问题不知道,只为了做任务,求楼主体谅