How many significant digits can a number have in CSS?

My question is, just how many (non-zero) decimal places can I include in the value I'm using in the CSS stylesheet before the browser rounds the number when interpreting it?

NOTE. I know that any decimal pixels are rounded (differently by different browsers) because subpixel units cannot be displayed on screens. What I am asking is, before this rounding takes place, the number of decimal places will be stored to start the browser's final calculations / roundings.

+3


source to share


1 answer


Whether it's truncation or rounding, in an ideal world, none of these events should happen. spec simply says that the numeric value can be composed of

  • one or more digits or
  • any number of digits followed by a period for a decimal point, followed by one or more digits.


The specification even takes into account the fact that a leading zero before the decimal point in a value that is less than 1 is not significant and thus can be omitted, for example. opacity: .5

... But there is no theoretical upper limit simply.

But due to implementation constraints, browsers will often "round" values ​​for rendering purposes. It is not something you can control other than by changing the precision of your values, and even then this behavior can change depending on the browser for obvious reasons and therefore you cannot rely on.

+4


source







All Articles