• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2463
  • Last Modified:

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
0
GhislainBruyere
Asked:
GhislainBruyere
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Ted BouskillSenior Software DeveloperCommented:
Have you tried Convert.ToFloat(oSPList.Items[0]["CalculatedField"].Value)
0
 
adiga123Commented:
convert this no to string and use  string.Trim() to remove until '#'.. now convert string to float and use
0
 
Ted BouskillSenior Software DeveloperCommented:
Two answers were provided and you did not give any feedback as to why they didn't succeed.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
GhislainBruyereAuthor Commented:
I would like a more flexible solution for other language.

I don't understand why oSPList.Items[0]["CalculatedField"].ToString() is language depedend
0
 
Ted BouskillSenior Software DeveloperCommented:
Why didn't you try my recommendation?  It is platform independent.
0
 
GhislainBruyereAuthor Commented:
Sorry missunderstoof
0
 
IkoexpertCommented:
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.
0
 
IkoexpertCommented:
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
                                                 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now