DataGrid CustomFormat numbers with 6 or less decmal places

input => 500,00380470201

<GridColumn Field=@nameof(Currency.Balance) 
                            HeaderText=@nameof(Currency.Balance) 
                            CustomFormat="@(new { type= "number", format= "0.######" })"
                            AllowFiltering="false"/>

this give the following output => 500,0038047020100000000
expected output => 500,003805

the grid is updated every 5 seconds with new input values



5 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team March 15, 2021 01:21 PM UTC

Hi Andreas, 

Greetings from Syncfusion. 

Query: DataGrid CustomFormat numbers with 6 or less decmal places 

We have validated your query and you want to show the numeric column values with 6 decimal places in Grid. You can achieve your requirement by using Format property. Find the below code snippets and sample for your reference. 

<SfGrid DataSource="@Orders" Height="315" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="N6" EditorSettings="@FreightEditParams" TextAlign="TextAlign.Right" Visible="true" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
    public IEditorSettings FreightEditParams = new NumericEditCellParams 
    { 
        Params = new NumericTextBoxModel<object>() { Decimals = 6, Format = "N6" }   //for setting while editing 
    }; 
 
 
    . . . 
} 


To show 6 decimal digits while editing, you can define by using EditorSettings. 

Reference

Please let us know if you have any concerns. 

Regards, 
Rahul 



AN Andreas March 15, 2021 02:22 PM UTC

hi,

yes but if i use N6 it will always show 6 decimal places even if they are all 0.

so in c sharp you can use the format 0.#(*n) for the option to show decimal places if they are filled


RN Rahul Narayanasamy Syncfusion Team March 16, 2021 01:13 PM UTC

Hi Andreas, 

Thanks for the update. 

Query: yes but if i use N6 it will always show 6 decimal places even if they are all 0. 

We have validated your query and we suggest you to provide the required Custom format in Format property. Since CustomFormat property is deprecated from v18.2.44. You can use Format property for this requirement. 

CustomFormat 
This property is deprecated. Use Format property to set column format. 

Find the below code snippets and sample for your reference. 

<SfGrid DataSource="@Orders" Height="315" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="0.######" EditorSettings="@FreightEditParams" TextAlign="TextAlign.Right" Visible="true" Width="120"> 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 



Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer

AN Andreas March 17, 2021 10:12 AM UTC

thanks, did not see the anouncement that the customformter is depricated, with Format="0.######" it is working fine. thanks


RN Rahul Narayanasamy Syncfusion Team March 18, 2021 05:36 AM UTC

Hi Andreas, 
 
Thanks for the update. 
 
We are happy to hear that the provided solution was helpful to achieve your requirement.  
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon