Formating numerical data

12 posts, 0 answers
  1. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 24 Jul 2007 Link to this post

    Hi Telerik,
    I need your support about formating numerical data into the datgrid. I made a search in your forum but I didn't find nothing, only information about data date type.
    So I wanna knoiw what about numerical data and type float for example.
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 24 Jul 2007 Link to this post

    Hi Najoua,

    Thank you for the question.

    You can set custom format on each column by using the column property DataTextFormatString. For example take a look on code snippet bellow:

            private void Form1_Load( object sender, EventArgs e )

            {

                DataTable dt = new DataTable();//make custom data source with 3 columns

                dt.Columns.Add( "col1", typeof( int ) );

                dt.Columns.Add( "col2", typeof( float ) );

                dt.Columns.Add( "col3", typeof( double ) );//add 3 rows with ID and PI number


                dt.Rows.Add( new object[] { 1, Math.PI, Math.PI } );

                dt.Rows.Add( new object[] { 2, Math.PI, Math.PI } );

                dt.Rows.Add( new object[] { 3, Math.PI, Math.PI } );

                        

                this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false;

     

                GridViewDataColumn col1 = new GridViewDataColumn( "col1" );

                this.radGridView1.MasterGridViewTemplate.Columns.Add( col1 );

     

                GridViewDataColumn col2 = new GridViewDataColumn( "col2" );

                this.radGridView1.MasterGridViewTemplate.Columns.Add( col2 );

                

    //here is the column number formating

    col2.DataTextFormatString = "{0:#}";//show only integer part of the number

     

                GridViewDataColumn col3 = new GridViewDataColumn( "col3" );

                this.radGridView1.MasterGridViewTemplate.Columns.Add( col3 );

     

    //here is the column number formating

     

    col3.DataTextFormatString = "{0:#.###}";//show 3 numbers after decimal point


                this.radGridView1.DataSource = dt;

            }

    For more information on formatting numbers and text, please review the following link.


    Regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 25 Jul 2007 Link to this post

    Hi,
    I have column in database with decimal(15,4) and bound to the grid.
    I try to format the grid column here using DataTextFormatString={0:g}
    It's NOT WORKING. How to use this format? BUT if i change it to DataTextFormatString={0:f} or others format, it works. Why?

    Please help.
  5. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 26 Jul 2007 Link to this post

    Thanks Peter,
    I will try this.I have another question.I saw that the SP2 radcontrols for winforms is available now and I wonder if I should rebuild all my application(using SP1) with SP2 controls or there is a way to keep the application and perform its using?
  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 26 Jul 2007 Link to this post

    Hello guys.

    Frederik, please read the following article carefully: http://idunno.org/archive/2004/14/01/122.aspx
    In this document you can find explanation how to format numbers – especially for {0:g} (g means general). Basically, the output  that you will get is the same as format string you have inserted, without any change.


    Najoua,
    if you feel there is no need to upgrade, i.e. SP1 performs fine in your project, there is no need to install and upgrade to SP2. Still, we will recommend using SP2 because we have added several new feature, and have fixed several major issues with our controls.

    If you want to use SP2 you have to uninstall SP1first and then install SP2. This will not impact your application, so you should update your project references to use the new assemblies. Basically, you should remove the old DLLs from your application and them again, but from SP2 installation.


    Best wishes,
    Peter
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  7. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 27 Jul 2007 Link to this post

    Hi Peter,
    I did like you said and I run the application.There is no error when debugging, but some foctionalities don't work.For exemple, I have a double click event in the grid view which occured the show of details row or imprting data...The problem is that that nothing is shown in defined area.
    Could you give some suggestion?
  8. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 27 Jul 2007 Link to this post

    Hi,

    Thanks for your help. Yes, I did read the website given. Please give me suggestion. I have table with 4 decimal point ex 100.2300 and in grid show 100.2300. Is it possible to take of the zeros and become 100.23 instead 100.2300 in the grid? The grid is bound to table in database

    Other case, value 100.2345 the grid have to show 100.2345.

    Please help. What format I have to use?
  9. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 27 Jul 2007 Link to this post

    Hi all,

    Eriksurya, if your column is bound as Decimal there is no need to remove any zeros. They are removed automatically. If this is a string column there is no possibility to  format the string with RadGridView.ValueFormatting. I would suggest specifying explicitly your column types in the DataSource. If you need additional help please open a support ticket and we will help you out.

    Bahri, we will need some more details in order to investigate your issue. Where exactly you are trying to attach on the double click event? Is it possible for you to send us your project? To do so, you must open a support ticket as well.

     
    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 03 Aug 2007 Link to this post

    Hi, telerik

    How to make the grid removes the decimal automatically? Because my grid doesnt do that. It's bound to table with decimal types. Even i use the datatextformatting in grid {0:g} and still doesnt work. I try {0:f} and it works.

  11. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 03 Aug 2007 Link to this post

    Hello eriksurya,

    Obviously, to give you an adequate explanation we will need to examine in more details your scenario. Could you please send us a small sample project so we could test it locally. Please note that to do this you should open a  support ticket.

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 06 Aug 2007 Link to this post

    Hi,

    After further investigation, if you set the data type in SQL SERVER 2005 to decimal (9,4), it will no automatically remove the zeros. And in the grid will show 4 decimal points.

    But if you choose float it will automatically remove the zeros and in the grid will show no zeros in decimal points.

    Then if I am using decimal data type how to achieve like float datatype in the grid?

    thanks

  13. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 07 Aug 2007 Link to this post

    Hello eriksurya,

    if you have decimal data type field in the underlaying database you should use GridViewTextBoxColumn or GridViewDecimalColumn depending on how you want to edit  values in the respective column in the grid.
    In the case of GridViewTextBoxColumn you will be able to edit with a simple textbox editor, while in case in GridViewDecimalColumn there will be a spin editor.

    Regardless of the type of column you will use, the formatting will be applied internally using the String.Format method. As the parameter pass the value from the DB as an object and the formatting string from the DataTextFormatString property from the column. You could see how String.Format works from this link: http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx
     

    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready