Reputation: 143
i have a string and i want to change it to number in javascript.
console.log(this.CountModel.get("count"));
var totalPages = parseInt(Math.ceil(this.CountModel.get("count") / numPerPage));
console.log(totalPages);
I used parsint but did not work. The first console return 200 which is right and the next console returns NAN. But how can I get the totalpages in number?
Thanks
Upvotes: 0
Views: 93
Reputation: 7632
You should parse the string before you try to calculate with it:
var totalPages = Math.ceil(parseInt(this.CountModel.get("count")) / numPerPage);
Assuming numPerPage
is already an Integer, and not zero (thanks to user1600124)
Upvotes: 1