简体   繁体   English

获取货币列表项目值

[英]Getting currency list item values

I have a list that contain two colums which are type currency. 我有一个包含两个colums类型货币的列表。 I want to be able to read the values from this field with the decimal places and the currecy symbol included. 我希望能够读取此字段中的值,并包含小数位和当前符号。

I have tried three different methods but I only seem to get the numbers and not the currecny symbol. 我尝试了三种不同的方法但我似乎只得到数字而不是currentcny符号。 Also decimal values are not being properly displayed. 十进制值也未正确显示。 The columns that use the decimal type are "InstallCosts" and "RentalCosts". 使用小数类型的列是“InstallCosts”和“RentalCosts”。

foreach (SPListItem item in listItemCollection)
{
try
{
string MPLS;
if ((bool)item["MPLS"])
MPLS = "Yes";
else
MPLS = "No";

//Conversion 1
double installCost;
bool convert1 = double.TryParse(item["InstallCosts"].ToString(), out installCost);

double rentalCost;
bool convert2 = double.TryParse(item["RentalCosts"].ToString(), out rentalCost);


//Conversion 2
string install = item["InstallCosts"].ToString();
double installConverted = double.Parse(install, NumberStyles.Currency,
CultureInfo.CurrentCulture.NumberFormat);

//Conversion 3
//string converThis = String.Format("[0:c}", (string)item["InstallCosts"]);


string results56 = (string)item["Title"] + " " + (string)item["DefinedFor"] + " " +
"<b>MPLS:</b> " + MPLS + "<br/>" + "<b>Max Downstream:</b> " + 
(string)item["MaxDownstream"] + "<br/>" + "Install Cost:" + converThis + "<br/>" 
+ "Rental Cost (p.a.):" + rentalCost + "<br/>";

AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(results56));
}

The result is the following: 结果如下:

Alpaca A dirty ADSL product for: CCTV third-party remote access interactive models and web site testing. 羊驼肮脏的ADSL产品用于:CCTV第三方远程访问交互模型和网站测试。 MPLS: No Max Downstream: Install Cost:50 Rental Cost (pa):425.7 MPLS:无最大下游:安装成本:50租赁成本(pa):425.7

The resuts for "Install Cost" should be : £50.00 The result for "Rental Cost" should be : £425.70 “安装成本”的结果应为:£50.00“租赁费用”的结果应为:£425.70

I have being stuck with this problem for a day now, would appreciate any assistance its probably something I am missing but I can't really see what! 我现在已经被这个问题困住了一天,会感谢任何帮助,这可能是我想念的东西,但我真的看不出来!

Many Thanks, 非常感谢,

In .net the numbers do not contain any currency or any other formatting information. 在.net中,数字不包含任何货币或任何其他格式信息。 So you have to add the currency symbol on your own: 所以你必须自己添加货币符号:

SPListItem item = ...;
double d = Convert.ToDouble(item["InstallCosts"]);
// will display the number in the current threads culture. In the US: $ <value>
string currency = d.ToString("C"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM