-
23 May 2012 7:41 PM #1
Answered: Howto format store float numbers with itempl?
Answered: Howto format store float numbers with itempl?
Whats a painless way to format float numbers out of a store using lists itempl?
The number format has to have a thousand separator e.g. 123.400 or 123'400 or 20,25.
I tried this, only with more pain
thanks, i kinda really need the numbers to be formated in the list...or any other ways how to get this done?Code:{[parseFloat(values.myfloatnumber)]}
thanks...Last edited by dishwashwebdesign; 23 May 2012 at 7:57 PM. Reason: whup, please place into: Sencha Touch 2.x: Q&A
-
Best Answer Posted by mitchellsimoens
I would use a member function. Your first post was close to that.
-
25 May 2012 2:25 AM #2
-
25 May 2012 8:21 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
First I would use type : 'float' in your model so it will already be float.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 May 2012 6:24 PM #4
Thanks for the reply, but the type is already set to 'float' in the model.
Thats why i am a bit lost why the numbers are displayed without any thousand separators...
-
26 May 2012 3:18 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
float numbers aren't going to have the thousands separator, you have to format it.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 May 2012 4:50 PM #6
Thanks, but that was the actual question, how to format float numbers inside a lists itemtpl. There is senchas Ext.Number and Ext.util.Format but they dont seem to do the trick either.
thanks for any further hints...
-
27 May 2012 5:10 PM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
There is no number formatter in Sencha Touch like there is in Ext JS. You will need to create one yourself.
Did a quick google search and this looks like it should work (didn't test):
Code:function addCommas(nStr) { nStr += ''; var x = nStr.split('.'), x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : '', rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 May 2012 5:24 PM #8
Thanks Mitchell,
I figured that one out too, this regex would do the trick as well:
my trouble is only how to squeeze the numbers thru the regex BEFORE itemtpl is rendering them out and aboutCode:x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
hope it makes sense now, thanks anyway for your assistance.
-
27 May 2012 5:26 PM #9Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
I would use a member function. Your first post was close to that.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 May 2012 5:46 PM #10
ah good one, thanks heaps that worked out just well:
Code:itemTpl: new Ext.XTemplate( '{[this.addCommas(values.remaining)]}', { compiled: true, addCommas: function (str) { return(str.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); } } ),


Reply With Quote