Negative currency values are shown in bracket

8 posts, 0 answers
  1. Coolasia
    Coolasia avatar
    19 posts
    Member since:
    Apr 2014

    Posted 06 Jul 2015 Link to this post

    Hi,

     I am using the {0:C} format for a number column in the grid, the positive values are showing correctly but when there are negative values they are shown in brackets for e.g. ($203.00) instead of -$203.00. I want to show the negative symbol instead of bracket also how to customize the currency symbol, I want to show text instead of symbol.

     Please suggest to fix the issue.

     Thanks in advance.

  2. Coolasia
    Coolasia avatar
    19 posts
    Member since:
    Apr 2014

    Posted 07 Jul 2015 in reply to Coolasia Link to this post

    Hi Admins,

     Can some one please reply to my above question.

    Thanks in advance.

  3. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 08 Jul 2015 Link to this post

    Hello Coolasia,

     

    Number formatting depends on the current culture which by default is en-US. For this culture negative currency formatting pattern is ($n) - which is the reason for the output you see.

     

    For this scenario you have the following choices:

     - override current culture negative pattern, i.e execute the following script before Grid initialization:

     kendo.culture().numberFormat.currency.pattern[0] = "-$n";

     

    You can find more details what those placeholders means here.

     

     - or define template for the column instead of format, i.e

    template: #=(data.myField < 0 ? '-$' : '') + Math.abs(data.myField) #"

     

    Regards,
    Nikolay Rusev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  4. Ricktor
    Ricktor avatar
    3 posts
    Member since:
    Aug 2020

    Posted 20 Aug 2020 in reply to Nikolay Rusev Link to this post

    Hi Nikolay,

    I have a specific question regarding negative Currency values being displayed in parenthesis. My requirement is to NOT show negative Currency Value (Payment) in parenthesis when the Payment was cancelled because in reality that amount was never deducted. Is there a way to handle this in Telerik? Any suggestions will be appreciated.

    Thanks,

    Ricktor.

  5. Petar
    Admin
    Petar avatar
    468 posts

    Posted 24 Aug 2020 Link to this post

    Hi Ricktor,

    If the targeted functionality is to not display the negative values in a given currency column, this functionality can be implemented using the following approach.

    First, we have to define a column template as follows:

    field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px", template: '#=getPrice(data)#' }

    The second step is to define the function that will return the correct Grid template. Here is the function I can suggest. The same can be implemented using a ternary operator

    function getPrice(data){
        if(data.UnitPrice < 0) {
        return '';
        }
        else return data.UnitPrice
    }

    The marked 'UnitPrice' field should be changed with the corresponding field in the context of your application. 

    Here is a Dojo example demonstrating the usage of the above code. Set negative values in the UnitPrice fields inside the Grid and see that the negative values will not appear.

    Regards,
    Petar
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

  6. Ricktor
    Ricktor avatar
    3 posts
    Member since:
    Aug 2020

    Posted 24 Aug 2020 in reply to Petar Link to this post

    Thanks Petar. However, I needed to omit parenthesis only for certain transactions in a currency value column (sucha as a cancelled transaction)... I didn't want a column with all values without paranthesis. This could be achieved by converting those specific values to positive which removes the paranthesis -- I could do this because this data is not shown for reporting purposes.

    Thanks,

    Ricktor.

  7. Petar
    Admin
    Petar avatar
    468 posts

    Posted 25 Aug 2020 Link to this post

    Hi Ricktor,

    I am not aware of the exact scenario in which you use the Grid. The purpose of the sample I've sent you was to demonstrate how we can use a cell template inside the Grid. Based on the targeted business logic, you can edit the definition of the getPrice function in a way it will return the expected by your business logic data.

    If it fits the business requirements of your applications, you can also convert the mentioned specific values to positive ones.

    Regards,
    Petar
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  8. Ricktor
    Ricktor avatar
    3 posts
    Member since:
    Aug 2020

    Posted 25 Aug 2020 in reply to Petar Link to this post

    Thanks Ricktor. I will try out your solution as well.

    Appreciate it.

Back to Top