View Full Version : [CLOSED] Razor - negitive number formats

Feb 13, 2013, 10:54 PM
Hi Guys

I had a good look around on extjs and ext.net but don't see this one. Is there a list of all the formats and is one of them for (0,000.00) which would represent a negative number. This is an accountancy style format.


Feb 13, 2013, 11:38 PM

Sorry, I don't quite understand what exactly is your problem with format, can you provide more information. To format value to accountancy style you can use Ext.util.Format.currency and it works with negative values too: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.Format-method-currency

Feb 14, 2013, 12:58 AM
So... data from database would be say -1.23 the renderer should then turn that into (1.23)

Feb 14, 2013, 1:05 AM
Yes, you can customize Ext.util.Format to do this.

If you have more questions about this I think it will be easier if you will provide some example and we can give you the best solution.

Feb 14, 2013, 5:41 PM
I have checked out the docs and searched the forums etc and can't see any syntax or example of formatting negative numbers like this , can you give me a tested example of ext.util.format representing a negative number as (1234.00) E.g. database gives -1234.00 and ext.util.format gives the result of (1234.00)

I really don't think I need to start reposting my MVC example with a number column added for half a line of code.

Feb 14, 2013, 11:45 PM
Sorry, I misunderstood your requirement.

Unfortunately, there is no number format to do what you want but you can use the following overriding to remove negative sign:

Ext.override(Ext.form.NumberField, {
setValue: function(v) {
if (v){
v = Ext.util.Format.number(v, '0,000.00');
v.replace(/^[+-]/, '');

return Ext.form.NumberField.superclass.setValue.call(this , v);

Feb 15, 2013, 12:12 AM
Thanks! i'll give it a try and let you know. Do you know if handling this type of formating will be included in the future?

Feb 15, 2013, 3:59 AM
Do you know if handling this type of formating will be included in the future?

I doubt. But it can be easily implemented with a common Column with a custom Renderer.