This is a migrated thread and some comments may be shown as answers.

Negative currency values are shown in bracket

7 Answers 2411 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Coolasia
Top achievements
Rank 1
Coolasia asked on 06 Jul 2015, 08:39 AM

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.

7 Answers, 1 is accepted

Sort by
0
Coolasia
Top achievements
Rank 1
answered on 07 Jul 2015, 09:04 AM

Hi Admins,

 Can some one please reply to my above question.

Thanks in advance.

0
Nikolay Rusev
Telerik team
answered on 08 Jul 2015, 06:52 AM

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!
 
0
Ricktor
Top achievements
Rank 1
answered on 20 Aug 2020, 03:40 PM

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.

0
Petar
Telerik team
answered on 24 Aug 2020, 10:51 AM

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).

0
Ricktor
Top achievements
Rank 1
answered on 24 Aug 2020, 02:33 PM

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.

0
Petar
Telerik team
answered on 25 Aug 2020, 10:31 AM

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/.

0
Ricktor
Top achievements
Rank 1
answered on 25 Aug 2020, 05:43 PM

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

Appreciate it.

Tags
Grid
Asked by
Coolasia
Top achievements
Rank 1
Answers by
Coolasia
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Ricktor
Top achievements
Rank 1
Petar
Telerik team
Share this question
or