KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to truncate a number in javascript, that means to cut away the decimal part: trunc ( 2.6 ) == 2 trunc (-2.6 ) == -2 After heavy benchmarking my answer is: function trunc (n) { return ~~n; } // or function trunc1 (n) { return n | 0; }
Tags (comma-separated)
Save Edits
Cancel