1

Why there is a difference between manually calculated height, and height calculated by the browser, using vh units. Because of this miscalculations i've got a problem at sub pixel level.

"1vh calculated by the browser: 5.34375px"
"1vh calculated using simple math: 5.3500000000000005"

And if 100vh is 535px then why there is this "...005" at the end when dividing by 100. There should be 5.35 and that's it, no weird digits after...

Test is in the fiddle.

https://jsfiddle.net/szpadel444/fdhvkygx/1/

Chudy444
  • 21
  • 2
  • 2
    these "wierd digits after" are an artfact of floating point number arithmetics (I guess you calculate it in JS). See for example http://stackoverflow.com/questions/588004/is-floating-point-math-broken – pawel Feb 23 '16 at 14:41
  • 1
    *"Because of this miscalculations i've got a problem at sub pixel level."*...then perhaps **that's** what needs addressing. – Paulie_D Feb 23 '16 at 14:41
  • it is flotting point error. see http://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript – murli2308 Feb 23 '16 at 14:49
  • ok this is new for me, but it's not the only case... Why those values are different? When browser calculates vh there is 0.00625 missing? @Paulie_D Also here is my subpixel problem https://jsfiddle.net/szpadel444/fdhvkygx/2/ – Chudy444 Feb 23 '16 at 18:18

0 Answers0