Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3669
  • Last Modified:

Formatting float value

I need to format float value like with C++ "%.03f" format, this means: 3 digits after decimal point, whole length is not defined. For example:

0.000
-15.120
1.007
...

float f = ...;
Console.WriteLine( ??? );
0
AlexFM
Asked:
AlexFM
1 Solution
 
existenz2Commented:
float f = -15.120;
string.Format("{0:0.000}",f);
0
 
bruintjeCommented:
Hello AlexFM,

another way

float f = 0.5f;
string x = f.ToString ("f3");

hope this helps a bit
bruintje
0
 
AlexFMAuthor Commented:
Thanks.
0:0.000 - I tried this before, this format gives exception.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now