W3C home > Mailing lists > Public > www-style@w3.org > December 2009

Numeric precision in CSS numbers

From: Simon Fraser <smfr@me.com>
Date: Tue, 22 Dec 2009 11:29:30 -0800
Message-id: <C9084C35-A9ED-44E6-96AB-60BE7F2ADEF0@me.com>
To: www-style list <www-style@w3.org>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 22 May 2012 03:47:12 GMT