I have a list that contain two colums which are type currency. 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. Also decimal values are not being properly displayed. The columns that use the decimal type are “InstallCosts” and “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. MPLS: No
Max Downstream:
Install Cost:50
Rental Cost (p.a.):425.7
The resuts for “Install Cost” should be : £50.00
The result for “Rental Cost” should be : £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. So you have to add the currency symbol on your own: