Software development tutorials, experiences and resources from developers in the day-to-day
There are so many people asking about a NumberField with ExtJS that allows them to add some aditional formatting to the numbers so i was using an extension that i found in the extjs forums but there were some unnecessary code – that i think, it was added because it was developed for an older version of ExtJS – so i decided to start from scratch my own class and add just the code for the functionality what i need.
1. Currency Symbol (by default is $), if you don’t need a currency symbol just set the config option to null or empty string:
To change the currency after the field was created you should use the function setCurrencySymbol.
2. Thousand separator with support for international format, you can use comma (,) or (.). If decimalSeparator is (,) then thousand separator will be (.) by default decimalSeparator is (.) and thousand separator (,). Also you cand hide thousand separator using the config option:
There are also a functions for setDecimalPrecision and setDecimalSeparator.
3. Display always all the decimals from the given decimal precision value the default value for this config option is:
If you are changing the properties after the field is created and don’t want or you can’t use the functions for any reason you must call updateNumberFormat function.
Here is an screenshot where you can see the diffent values formatted using the extension:
Hope you like it.
The source code is available here.