How can I format a calculated column to a fixed number of decimal places

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?


Attachment: SyncfusionQueryCalculatedColumn_58667a8c.zip

3 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team February 13, 2024 12:53 PM UTC

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>




Sample Link: https://blazorplayground.syncfusion.com/embed/rjhTXrsAprESkvzx?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

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


Marked as answer

CB Christopher Bell February 13, 2024 02:32 PM UTC

Brilliant - thank you so much.  (Easy when you know how!)



GE Getsy Edwin Syncfusion Team February 14, 2024 09:30 AM UTC

Christopher,

You're welcome!! Please feel free to contact us for further assistance.


Loader.
Up arrow icon