This is a migrated thread and some comments may be shown as answers.

RadGrid number formatting

6 Answers 1936 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex Yung
Top achievements
Rank 1
Alex Yung asked on 23 Oct 2008, 08:17 AM
Dear Telerik Support Team,

I have some decimal number on one column, but when it is smaller than 1 (such as 0.014836583), the display value in the RadGrid is .014836583. How can I format it? I have try DataFormatString, but it fails.

Any help is highly appreciated!

Regards,
Alex

6 Answers, 1 is accepted

Sort by
0
Missing User
answered on 23 Oct 2008, 08:45 AM
Hello Alex,



To see more information on the requested functionality, please refer to the following online demo:

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alex Yung
Top achievements
Rank 1
answered on 23 Oct 2008, 09:10 AM
Dear Plamen ,

Thanks for your reply. However, the link provided does not show me how to show the leading zero.

Regards,
Alex
0
Missing User
answered on 23 Oct 2008, 09:28 AM
Hello Alex,

Float numbers between zero and one can be formatted in two ways, with or without leading zero before decimal point. To format number without a leading zero use # before point. For example „#.0“ formats number to have one decimal place and zero to N digits before decimal point (e.g. „.5“ or „123.5“).

Following code shows how can be formatted a zero (of double type).

String.Format("{0:0.0}", 0.0);            // "0.0" 
String.Format("{0:0.#}", 0.0);            // "0" 
String.Format("{0:#.0}", 0.0);            // ".0" 
String.Format("{0:#.#}", 0.0);            // "" 
 



Greetings,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alex Yung
Top achievements
Rank 1
answered on 23 Oct 2008, 09:39 AM
Hi Plamen,

You mean I should use string in the RadGrid? When I apply the style into DataFormatString in RadGrid, it cannot work.

Thanks,
Alex
0
Princy
Top achievements
Rank 2
answered on 23 Oct 2008, 02:08 PM
Hello Alex,

You can try setting the DataFormatString in the code behind as shown below.
cs:
   GridBoundColumn col = RadGrid1.Columns.FindByUniqueName("Age") as GridBoundColumn; 
         
    // access the cell value  
      col.DataFormatString = string.Format("{0:#.###}", value); 

Thanks
Princy.
0
Alex Yung
Top achievements
Rank 1
answered on 24 Oct 2008, 01:04 AM
Hi Princy,

This must be set in program? I want to apply this in Design Time when I define every column. When I set {0:0.###} to DataFormatString at the design view, it just dun work. Any idea?

Thanks,
Alex
Tags
Grid
Asked by
Alex Yung
Top achievements
Rank 1
Answers by
Missing User
Alex Yung
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or