1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default 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
    Code:
    {[parseFloat(values.myfloatnumber)]}
    thanks, i kinda really need the numbers to be formated in the list...or any other ways how to get this done?
    thanks...
    Last edited by dishwashwebdesign; 23 May 2012 at 7:57 PM. Reason: whup, please place into: Sencha Touch 2.x: Q&A

  2. I would use a member function. Your first post was close to that.

  3. #2
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


    anyone? any hints at all?

  4. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  5. #4
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


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

  6. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  7. #6
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


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

  8. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  9. #8
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


    Thanks Mitchell,
    I figured that one out too, this regex would do the trick as well:
    Code:
    x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    my trouble is only how to squeeze the numbers thru the regex BEFORE itemtpl is rendering them out and about
    hope it makes sense now, thanks anyway for your assistance.

  10. #9
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  11. #10
    Sencha User
    Join Date
    Oct 2011
    Posts
    53
    Vote Rating
    0
    Answers
    3
    dishwashwebdesign is on a distinguished road

      0  

    Default


    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, ","));
                            }
                        } 
                    ),