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

Format for numeric columns

6 Answers 329 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oscar
Top achievements
Rank 1
Oscar asked on 10 Oct 2011, 12:42 PM
I'm using .Format("{0:Nn_number_of_decimals}") to format my numeric columns in a grid. If format is {0:N}, it works perfectly. It shows symbol separator depending on cultureInfo and two decimal places correctly. But if the format of the column is {0:N0} or {0:N3} for example, because the column has no decimal positions or has 3 decimal places, it doesn't work.
CustomFormatRegEx considers N0 as a custom Format.
N1, N2, N3 and so on are considered as Not Custom formats but it doesn't take into account de number of decimal positions.
Wouldn't $t.formatNumber function in telerik.common.js be something like this?

switch (format.toLowerCase()) {

case 'd':

return Math.round(number).toString();

case 'c':

type = 'currency'; break;

case 'n': type = 'numeric'; break;

 

// added code: up to 9 decimal places. 

 case 'n0':

 case 'n1':

 case 'n2':

 case 'n3':

 case 'n4':

 case 'n5':

 case 'n6':

 case 'n7':

 case 'n8':

 case 'n9':

     type = 'numeric'; if (!digits) digits = format.substring(1); break;

 // end added code

 

case 'p':

type = 'percent';

if (!isTextBox) number = Math.abs(number) * 100;

break;

default:

return number.toString();

}


http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#NFormatString

Sample of grid:

 

 

 

.Columns(Sub(columns)
            columns.AutoGenerate(False)
            columns.Bound(Function(bound) bound.ProductId()).Width(80)
            columns.Bound(Function(bound) bound.Description()).Width(300)
            If ViewBag.LoadExpirationDate Then
               columns.Bound(Function(bound) bound.ExpirationDate()).Width(100).Format("{0:d}").EditorTemplateName("Date")
               columns.Bound(Function(bound) bound.Price()).Width(150).Format("{0:N3}").EditorTemplateName("Currency")
               columns.Bound(Function(bound) bound.Quantity()).Width(150).Format("{0:N0}")
            End If
         End Sub) _
.DataBinding(Sub(dataBinding)
                dataBinding.Ajax() _
                           .OperationMode(GridOperationMode.Client) _
                           .Select("LoadData", "Home") _
                           .Update("Save_Batch", "Home")
             End Sub) _

.

Do you have any solution?

 

6 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 11 Oct 2011, 12:52 PM
Hello Oscar,

 
As you mentioned $.telerik.formatNumber does not support "{0:N_number}" format. I am glad to inform you that we addressed this limitation right after Q2 2011 SP1 release. N format will is now supported and will be available with the next internal build of Telerik Extensions for ASP.NET MVC.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Oscar
Top achievements
Rank 1
answered on 12 Jan 2012, 11:23 AM
Hello Georgi:
Q3 2011 didn't adress this limitation as you told me.
0
Georgi Krustev
Telerik team
answered on 12 Jan 2012, 12:16 PM
Hello Oscar,

 
You will need to use "{0:n0}" format. Currently {0:N0}" is not supported, as it is considered as a custom format. This issue is addressed and the fix will be available in the Q1 2012 release of Telerik Extensions for ASP.NET MVC scheduled for the mid of February.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Oscar
Top achievements
Rank 1
answered on 12 Jan 2012, 12:29 PM
Hi Georgi,
I'm looking forward to Q1 2012!
0
Bryan
Top achievements
Rank 1
answered on 28 Mar 2012, 03:16 PM
If you are trying to display the currency symbol, you can use the following:

 

.Format("{0:c}")

or
.Format(
"${0:n2}")
0
Bryan
Top achievements
Rank 1
answered on 28 Mar 2012, 04:03 PM
I guess you can disregard.. A little late. Looks like the updates did it.. :)
Tags
Grid
Asked by
Oscar
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Oscar
Top achievements
Rank 1
Bryan
Top achievements
Rank 1
Share this question
or