IE rips decimals after two places?

2019-08-25 12:47发布

I have a situation where i'm giving width to a div dynamically using jQuery. Everything is working good with moz and ff since they are taking 100/7+"%" as 14.2857% where as IE is taking it as 14.28% which is screwing up my UI as 14.28*7 is only 99.96.

is there a solution to make my ie take three or four decimals?? I've tried rounding my output to three, also tried using toFixed(3) which are not working.

Thanks in advance.

1条回答
Summer. ? 凉城
2楼-- · 2019-08-25 13:30

I would recommend that you work in pixels instead. Since you are using jQuery anyway, you have access to $(window).width() and $(screen).width(), or $(parentelement).width() so there's your 100%. Then all pixel measurements are guaranteed to be integer by definition.

then

$("#mydiv").width($(window).width() / 7);

Maybe not the solution you wanted but we have all our developers work in pixels as a standard. We find that works well in practice.

查看更多
登录 后发表回答