Formatting as an integer still has 2 decimal places

sfDataGrid1.Columns["ID"].Format = "C";

It will still display 2 decimal places My columns are automatically read from the database. I don't want decimals


7 Replies 1 reply marked as answer

YM yu ma May 8, 2023 08:50 AM UTC

sfDataGrid1.Columns["ID"].Format = "0";





VS Vijayarasan Sivanandham Syncfusion Team May 8, 2023 10:13 AM UTC

Hi Yu ma,

When defining a currency format in a GridColumn, the default behavior of the Currency format is to display currency values with two decimal places. Therefore, if you are seeing decimal values in the GridColumn, this is the expected behavior and not a problem.

However, if you want to display currency values without decimal places, you can achieve this by defining a custom format as shown below:

// Define the currency format for the column with zero decimals.

sfDataGrid1.Columns["ID"].Format = "C0";           


By setting the Format property to "C0", the currency value will be displayed without any decimal places in the GridColumn. You can adjust the number 0 in the format string to display the desired number of decimal places.

For more information related to GridNumericColumn, please refer to the below user guide documentation link,


UG Link: https://help.syncfusion.com/windowsforms/datagrid/columntypes#gridnumericcolumn

https://help.syncfusion.com/windowsforms/datagrid/columntypes#custom-formatting

Find the sample demo in the attachment.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_21453620.zip


YM yu ma May 8, 2023 12:10 PM UTC

thank you



VS Vijayarasan Sivanandham Syncfusion Team May 9, 2023 06:36 AM UTC

Yu ma,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.



YM yu ma replied to Vijayarasan Sivanandham May 9, 2023 02:31 PM UTC

你好

是否有更改自动生成列的列类型的情况



VS Vijayarasan Sivanandham Syncfusion Team May 10, 2023 04:14 PM UTC


Marked as answer

YM yu ma May 12, 2023 02:05 AM UTC

thank you



Loader.
Up arrow icon