Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

devexpress

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

like image 682
P a u l Avatar asked Apr 25 '09 00:04

P a u l


2 Answers

yourNumber.ToString("N2");
like image 172
LukeH Avatar answered Nov 15 '22 17:11

LukeH


You can use syntax like this:

String.Format("{0:0.00}", n)
like image 28
Vadim Avatar answered Nov 15 '22 17:11

Vadim