tags:

views:

2228

answers:

6

I need to display float as

1.00
1.50
1.55
1.60

The following is what I see using f2 format.

1.
1.5
1.55
1.6

Is there a way to force the trailing 0 to appear?

(I'm using a DevExpress SpinEdit control and trying to set the display and edit format.)

+4  A: 

You can use syntax like this:

String.Format("{0:0.00}", n)
Vadim
+6  A: 
yourNumber.ToString("N2");
LukeH
A: 

For future reference,

http://www.csharp-examples.net/string-format-double/

z3r0 c001
A: 

TY for all the correct responses. Fixed this by setting spinEdit.Properties.EditMask to N2.

P a u l
+2  A: 

On those rare occasions I need to formatting, I go here:

http://blog.stevex.net/index.php/string-formatting-in-csharp/

cookre
Ditto. :) 
Chris
+2  A: 
spinEdit.Properties.DisplayFormat.FormatType = FormatType.Numeric;
spinEdit.Properties.DisplayFormat.FormatString = "C2";

In the future, though, I would recommended searching Dev Express' knowledge base or emailing support ([email protected]). They'll be able to answer your question in about a day.

Josh Kodroff