1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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 Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #4
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  7. #6
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  9. #8
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I would use a member function. Your first post was close to that.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  11. #10
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    61
    Answers
    3
    Vote Rating
    0
    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, ","));
                            }
                        } 
                    ),

Thread Participants: 2

Tags for this Thread