Tutorial :c#: how to force trailing zero in numeric format string?



Question:

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.)


Solution:1

yourNumber.ToString("N2");  


Solution:2

You can use syntax like this:

String.Format("{0:0.00}", n)  


Solution:3

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

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


Solution:4

For future reference,

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


Solution:5

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 (support@devexpress.com). They'll be able to answer your question in about a day.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »