Reputation: 24112
How can I simple delete everything after a decimal place including the decimal so I am left with a whole number?
I.e. 325.6899
needs to be 325
with no rounding.
Ideally I'd like a function that does this but I don't know of any in Javascript.
Upvotes: 0
Views: 107
Reputation: 1675
Here's another;
var result = 325.689 - 325.689 % 1;
Probably not faster than floor nor better but it works.
Upvotes: 0
Reputation: 15393
Another different answer
var foo = 325.689;
console.log(Number(foo.toString().split(".")[0])); // = 325
Upvotes: 0
Reputation: 337560
You can use Math.floor
:
var foo = Math.floor(325.689);
console.log(foo); // = 325
Upvotes: 5