[英]How can I save my Sharepoint list value as currency/decimal?
I have an item/member of a Sharepoint 2010 list that is declared as data type CUrrency: 我有一个Sharepoint 2010列表的项目/成员,该项目/成员声明为数据类型CUrrency:
list.Fields.Add("Section5Total", SPFieldType.Currency, false);
Yet, when I try to save a currency value into that member, it won't compile. 但是,当我尝试将货币值保存到该成员中时,它将无法编译。 This:
这个:
spli["Section5Total"] = (SPFieldCurrency)boxSection5Total.Text;
...gives me, ...给我,
Cannot convert type 'string' to 'Microsoft.SharePoint.SPFieldCurrency'
无法将类型“字符串”转换为“ Microsoft.SharePoint.SPFieldCurrency”
This: 这个:
spli["Section5Total"] = (decimal)boxSection5Total.Text;
...similarly tells me I can't convert String
to Decimal
. ...类似地告诉我,我无法将
String
转换为Decimal
。
I get that the compiler is not going to look at "Section5Total" and figure out that it has been declared as a Currency SPFieldType
. 我知道编译器不会查看“ Section5Total”并发现它已被声明为Currency
SPFieldType
。 Yet this: 但这:
spli["Section5Total"] = 0.0;
...compiles just fine. ...编译正常。 So why does it accept a literal float val, but not a cast one?
那么,为什么它接受字面量的float val,而不接受强制转换的float val?
You cannot cast a string to decimal. 您不能将字符串强制转换为十进制。 Try:
尝试:
spli["Section5Total"] = Convert.ToDecimal(boxSection5Total.Text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.