Numeric precision in CSS numbers

The section on Numbers in CSS3 Values and Units at <http://www.w3.org/TR/css3-values/#numbers> says nothing about numeric precision, other than some wording about values being restricted to a range for some properties.

For integers, it isn't stated how large values can get before they fail to parse, or fail to round-trip; for floating point values, it isn't specified how many significant digits are retained by parsing, and round-tripping. (By round-tripping, I mean setting the value via the CSS OM, and then reading it back.)

For both large integers and floating point values with many decimal places, implementations behave differently. Both WebKit and Gecko fall into scientific notation in some cases (e.g. set 'left' to '12345678px', and reading it back will give you '1.23457e+7px' which fails to parse if you in turn try to use it to set the value); Opera does not. WebKit and Gecko also retain 6 significant digits for floating point values; Opera, on the other hand, rounds to two decimal places.

This is a real-world issue. When we changed our number formatting in WebKit, we broke a site <https://bugs.webkit.org/show_bug.cgi?id=32078>. Also, we need to be able to round-trip floating point numbers with high precision for CSS transforms.

There is a test page here (but note that it doesn't work in Opera because of value limiting):
<https://bug-30341-attachments.webkit.org/attachment.cgi?id=45276>

I think there are two things that we need to do:
1. Be more explicit about the behavior of round-tripping large integer values, and floating point values with lots of significant digits.
2. Ensure that the CSSValue replacement in CSS OM allows authors to modify style without going through number/string conversions, and therefore losing precision.

Simon

Received on Tuesday, 22 December 2009 19:30:04 UTC