meteor - Error when adding commas to number -


i'm trying helper return number commas (eg 100000 = 100,000). returning correctly getting error appearing in console.

exception in template helper: typeerror: cannot read property 'tostring' of undefined

if console.log(value); returns undefined.

path: test.js

template.registerhelper(     'formatcurrency', function(value) {     return value.tostring().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");     }, ); 

path: test.html

{{formatcurrency comparesalary.usersalary}} {{formatcurrency comparesalary.min}} 

a common failure in helpers data isn't subscription time try render it. can prevented testing value before returning it:

template.registerhelper(   'formatcurrency',(value)=>{     return value && value.tostring().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");   }, ); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -