Link to home
Start Free TrialLog in
Avatar of GhislainBruyere
GhislainBruyereFlag for Belgium

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]["CalculatedField"].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
ASKER CERTIFIED SOLUTION
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adiga123
adiga123

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.
Avatar of GhislainBruyere

ASKER

I would like a more flexible solution for other language.

I don't understand why oSPList.Items[0]["CalculatedField"].ToString() is language depedend
Why didn't you try my recommendation?  It is platform independent.
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.GetFormattedValue("SP_CALCULATED_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