We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Format a currency column

Hi

I want to set the format of currency, with negatives values, if the value of the column is -200, I want that the result is -$200, rigth now it shows that the value is ($200)

5 Replies

KK Karthick Kuppusamy Syncfusion Team September 27, 2016 01:29 PM UTC

Hi Dayne, 

Thanks for Contacting Syncfusion Support. 

We have analyzed your requirement and while we set the negative value for the currency column the jquery currency format will be automatically convert the negative value to the parenthesis value. 

This is the default behavior. 

Please find the link for your reference. 

Regards, 
K.Karthick. 



DA Dayne September 27, 2016 02:22 PM UTC

Hi, but I don't want the default behavior, I want the negative result, for example:

If the value is: 200 the result sould be $200.00

If the value is: -200 the result sould be -$200.00 instead of ($200)

Is this posible?


KK Karthick Kuppusamy Syncfusion Team September 29, 2016 08:37 AM UTC

Hi Dayne, 

We have analyzed your requirement and we can change the format for Currency values through the QueryCellInfo event of the grid. 

Please find the code example. 

@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        . 
        . 
        . 
        .EditSettings(edit=>{edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
         .ClientSideEvents(e => e.QueryCellInfo("QueryCellInfo")) 
         .Columns(col => 
          { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); 
            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add(); 
             
        })) 
</div> 
 
<script>  
    function QueryCellInfo(args) { 
        if (args.column.field == "Freight" && args.data.Freight < 0) { 
            args.cell.innerHTML = "-" + ej.format(args.data.Freight * -1, "C2"); 
        } 
    } 
</script> 


For your reference we have created a sample based on your requirement and same it can be downloaded from the following location. 

Please refer the following UG Link for more information. 

Regards, 
K.Karthick. 



DA Dayne September 29, 2016 01:42 PM UTC

Thanks very much, this solucion works fine.


KK Karthick Kuppusamy Syncfusion Team September 30, 2016 03:28 AM UTC

Hi Dayne, 

Thanks for the update. 

We are happy to hear that your requirement is achieved. 

Regards, 
K.Karthick. 


Loader.
Up arrow icon