?: doesn't work correctly in javascript -


i written following code change numbers persian:

function farsi(x) {     x = x.tostring().replace(/\b(?=(\d{3})+(?!\d))/g, ",");     var = '۰۱۲۳۴۵۶۷۸۹'; var b = '';      (var = 0; < x.length; i++) {          var c = x.charcodeat(i);          b += (c >= 48 || c <= 57 ? a.charat(c - 48) : x.charat(i));      }      return b;  } 

i have used regex thousand seprator how print number commas thousands separators in javascript works correctly. separator character not being added in line of code:

b += (c >= 48 || c <= 57 ? a.charat(c - 48) : x.charat(i)); 

here fiddle

you put || instead of &&

b += (c >= 48 && c <= 57 ) ? a.charat(c - 48) : x.charat(i); 

see working code https://jsfiddle.net/4qvwzs5e/2/


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -