Click here to Skip to main content
11,717,883 members (80,958 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# string
How to convert string to float.

i have to use it to set the size of Label
this.lblComanyName.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
Posted 9-Oct-12 9:53am
Wes Aday at 9-Oct-12 16:07pm
did you try float.Parse()?
Sergey Alexandrovich Kryukov at 9-Oct-12 16:08pm
I don't believe so, so I decided to answer...
Sergey Alexandrovich Kryukov at 9-Oct-12 16:07pm
As if MSDN was broken, honestly...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This not "convert" (this word is a real curse of CodeProject inquirers, I don't know why), this is "parse":[^],[^],[^],[^],[^],[^].

And yes, for most applications you really want to use double, not Single. For System.Single (alias float), all methods are the same:[^].

The difference the "Try…" forms of methods make is that they do not throw exceptions, ever. (They do not throw and then catch as I thought, they don't throw at all; I checked up this implementation detail by source code.) Instead, you check up the return values to see if the parsing is successful or not.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 849
1 OriginalGriff 215
2 F-ES Sitecore 210
3 Maciej Los 140
4 Jochen Arndt 120
0 Sergey Alexandrovich Kryukov 1,494
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100