GhislainBruyere
asked on
Convert SharePoint Number to C# Float
Hello,
I've a SharePoint Site in French (SP 2007). On this machine, Windows is also in French.
In a list, I've a calculated field with the data type "Nombre" (number) with 2 decimals.
When I get this number in C# : oSPList.Items[0]["Calculat edField"]. ToString() , I have this string "float;#0.23454" and of course I can't convert it to C# float.
How can I convert a number from french SharePoint to a float C# ?
Thanks in advance
Ghislain
I've a SharePoint Site in French (SP 2007). On this machine, Windows is also in French.
In a list, I've a calculated field with the data type "Nombre" (number) with 2 decimals.
When I get this number in C# : oSPList.Items[0]["Calculat
How can I convert a number from french SharePoint to a float C# ?
Thanks in advance
Ghislain
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
convert this no to string and use string.Trim() to remove until '#'.. now convert string to float and use
Two answers were provided and you did not give any feedback as to why they didn't succeed.
ASKER
I would like a more flexible solution for other language.
I don't understand why oSPList.Items[0]["Calculat edField"]. ToString() is language depedend
I don't understand why oSPList.Items[0]["Calculat
Why didn't you try my recommendation? It is platform independent.
ASKER
Sorry missunderstoof
Using SP2010 and ran into the same issue. There is no Value() method for SPListItem["fieldname"] and there is no Convert.ToFloat() either. Any suggestion? Thanks much.
ok, in SP2010 you can achieve this by:
double c_sharp_number = 0;
bool success = double.TryParse(SPListItem .GetFormat tedValue(" SP_CALCULA TED_NUMBER "), out c_sharp_number);
The SP field "SP_CALCULATED_NUMBER" has the following string value "float;#12.80000". c_sharp_number has the value 12.8
HTH
double c_sharp_number = 0;
bool success = double.TryParse(SPListItem
The SP field "SP_CALCULATED_NUMBER" has the following string value "float;#12.80000". c_sharp_number has the value 12.8
HTH