hi Shyamsundar,
Your #1 is plain unworkable. have a look at the i18n <https://docs.angularjs.org/guide/i18n>stuff from angular. I think for most of what you need you just need to load another locale. Your #2 will work. And while your sample will take (on first sight) in account most, if not all, edge-cases, it is a lot of code. It might be that you need all of this, but for just some number formatting, it is a lot. Most users will never hit the exponents. And while it’s very flexible, and you can choose whatever formatting you like, it might be a better idea to just code for the case you have, in stead of creating a solution for every possible use-case. meaning, if you have 2 numbers to display on the page, this is not an issue. If you have to display a few hundreds of numbers, all those extra processing cycles will add up. a simple formatter like this: function myFormat() { return myFormatter; function myFormatter(num) { if (!angular.isNumber(num)) { // don't process anything that's not a number return num; } var string=''+Math.round(+num * 100); var len = string.length; var l = len; var result = []; while (--l>-1) { result.unshift('' + string[l]); if (len-l===2) { //decimail point result.unshift(','); } else if (l > 0 && (len-l-2)%3 === 0 ) { // separator result.unshift('.'); } } return result.join(''); } } Will do in most cases, (see it in action <http://plnkr.co/edit/nGiq04ND8TS3gsL3ELmd?p=preview>) Does this help a bit? Regards Sander -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
