How to set the number of decimal places for a numeric/double field?

Using the SfDataForm in Xamarin.Forms it was easy to set the number of decimal places for a numeric/double field using the MaximumNumberDecimalDigits property.

How do I achieve the same effect in the .NET MAUI SfDataForm control?

Thanks.


1 Reply

VM Vidyalakshmi Mani Syncfusion Team August 31, 2023 10:08 AM UTC

Hi Iain,


You can achieve your requirement by using the `CustomFormat` property, which is used to specify the formatting of the editor's value. Please refer to the following code snippet for your reference:


Code snippet:

 

this.dataForm.GenerateDataFormItem += OnGenerateDataFormItem;

 

private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs e)

{

    if (e.DataFormItem != null && e.DataFormItem.FieldName == "Amount" && e.DataFormItem is DataFormNumericItem numericItem)

    {

        numericItem.CustomFormat = "#,0.00##"; // To display a minimum of 2 decimal digits and a maximum of 4 digits, with grouping.

        numericItem.CustomFormat = "#,#.#"; // To display a maximum of 2 decimal digits, with grouping.

        numericItem.CustomFormat = "#"; // To display values with no decimal digits.

    }

}

 


We hope that this helps you. Please let us know if you need further assistance.



Loader.
Up arrow icon