Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE browser not supporting Math.trunc()

Tags:

javascript

The below code is working fine in Chrome, but in IE browser I am seeing the below console error:

object does not support property or method 'trunc'

Code:

var Days = (new Date(date1) - new Date(date2)) / 50;
if (Math.trunc(Days) > 45)) {
 alert("it should be less than 45 days");
}
like image 821
Dev Avatar asked May 11 '26 07:05

Dev


1 Answers

Math.trunc is not supported in IE as MDN states, please read here.

Instead you could use polifylls:

if (!Math.trunc) {
    Math.trunc = function (v) {
        return v < 0 ? Math.ceil(v) : Math.floor(v);
    };
}

Hope that clarifies.

like image 99
norbitrial Avatar answered May 12 '26 20:05

norbitrial



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!