Mathlight Mathlight - 4 years ago 328
C# Question

What is the C# equivalent to Delphi's FormatFloat?

I'm porting some Delphi code to C#. I can't find a similar function to Delphi's

FormatFloat
.

I've got this line of code in Delphi

str := FormatFloat('000', 1);


which assigns to
str
the string
'001'
. Note the leading zeros.

How can I achieve the same result in C#?

Answer Source

You use string.Format() with custom numeric format strings. For example:

int a = 1;
string.Format("{0:000}", a); // returns "001"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download