imperium2335
imperium2335

Reputation: 24112

Strip and ignore decimals in javascript

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

Answers (4)

Felix Castor
Felix Castor

Reputation: 1675

Here's another;

var result = 325.689 - 325.689 % 1;

Probably not faster than floor nor better but it works.

Upvotes: 0

Sudharsan S
Sudharsan S

Reputation: 15393

Another different answer

var foo = 325.689;
console.log(Number(foo.toString().split(".")[0])); // = 325

Fiddle

Upvotes: 0

Prabhu Murthy
Prabhu Murthy

Reputation: 9261

you can simply do

parseInt(325.6899);

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337560

You can use Math.floor:

var foo = Math.floor(325.689);
console.log(foo); // = 325

Upvotes: 5

Related Questions