Convert float to string with comma and dot
12,925
A solution for this can be the following:
float? num = 1.2f;
string floatAsString = string.Format("{0:f}", num.Value);
Maybe you need to check if the HasValue
property is true
before you use the value. For more examples: http://alexonasp.net/samples/stringformatting/
Author by
holzleube
Updated on June 04, 2022Comments
-
holzleube almost 2 years
I have a nullable float. The internal decimal places can be separated with dot or comma e.g. 1.2 or 1,2. I need this float as a string to compare it to a Regex. If I use the Convert.toString method, the float with the comma is 12 and not 1.2. How can I convert a float to String without loosing the comma or the dot? I alredy tried to convert it with diffrent cultures.
Thanks for your help