How can I format a calculated column to a fixed number of decimal places
3 Replies
SIGN IN To post a reply.
I am following the example of how to "Calculate Column Value Based on Other Columns in Blazor DataGrid" as per the Syncfusion example (https://blazor.syncfusion.com/documentation/datagrid/how-to/calculate-column-value-based-on-other-columns), and would like the calculated column to be formatted to 3 decimal places. (My data is Decimal type.) I notice that in your example the calculated column is supposed to be formatted 'c2' but doesn't show trailing zeros. (See screenshots attached)
Is there a way to format the calculated column and show trailing zeros?
Hi Christopher,
Based on the problem you reported, we would like to clarify that the template
feature is designed solely for display purposes. Therefore, in the grid format,
it does not display the value as this is the default behavior. To achieve your
requirement, please refer to the following code snippet and sample for your
reference.
|
<GridColumn Field=@nameof(Order.FinalCost) HeaderText="Final price" TextAlign="TextAlign.Center" Width="120"> <Template> @{ var value = (context as Order); var finalAmount = value.ManfCost + value.LabCost; decimal finalAmountDouble = Convert.ToDecimal(finalAmount); string finalAmountString = finalAmountDouble.ToString("F2"); // Use "F2" for two decimal places <div>$@finalAmountString</div> } </Template> </GridColumn>
|
Also, we have logged an internal bug task in our UG documentation. We will include the correction in our UG documentation in one of our upcoming patch releases. Therefore, we kindly request you to periodically visit our website for documentation updates.
Regards,
Prathap S
Brilliant - thank you so much. (Easy when you know how!)
Christopher,
You're welcome!! Please feel free to contact us for further assistance.