简体   繁体   English

如何将我的Sharepoint列表值另存为货币/小数?

[英]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.

相关问题 如何将十进制属性格式化为货币? - How can I format decimal property to currency? 如何将文本框(输入==文本)中的值另存为Sharepoint中的“货币”值? - How can I save values from a textbox (input == text) as Currency values in Sharepoint? 如何设置无小数位数但只有小数为零时的货币格式? - How can I format currency with no decimals but only when the decimal is zero? 如何根据我的小数位置值显示小数位? - How can I display decimal position based on my decimal position value? 我可以使用printf()将十六进制转换为十进制并保存值吗? - Can I use printf() to convert hex to decimal and save the value? 如何使用我的appSettings配置文件中的值,并在构造函数方法中将其用作十进制值? - How can i use a value from my appSettings Configuration file, and use it in a constructor method as a decimal value? 如何将小数与硬编码值进行比较? - How can I compare a decimal with a hardcoded value? 如何将“,”替换为“。” 以十进制还是浮点数表示? - How can I replace “ , ” to “ . ” in decimal or float value? 我如何用巴基斯坦货币表示 256359 这样的值 - how can i express value like 256359 in pakistan currency 如何从共享点站点中读取列表并使内容在代码中全局可用? - How can I Read a list from a sharepoint site and make the contents globaly available in my code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM