Fez Vrasta
Fez Vrasta

Reputation: 14815

max number of decimals allowed by CSS transform scale?

I'm trying to reduce the number of decimals of a JS operation and use the result to set a transform: scale(x) inline CSS to an element.

I can't find any reference to know how many decimals are allowed by such CSS function.

I want to know how many numbers are allowed (and used by the browser in the transformation) after the comma. (0.0000000N)

Upvotes: 2

Views: 3538

Answers (2)

Heretic Monkey
Heretic Monkey

Reputation: 12113

The specification defines the value for scale as a <number>, which is defined as:

A number is either an <integer> or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits and optionally an exponent composed of "e" or "E" and an integer. It corresponds to the <number-token> production in the CSS Syntax Module [CSS3SYN]. As with integers, the first character of a number may be immediately preceded by - or + to indicate the number’s sign.

Note the lack of how many "more" decimal digits are allowed. So any limit will be imposed by the browser, which will obviously vary by browser.

Upvotes: 6

Vi100
Vi100

Reputation: 4203

As it seems it could be useful for others and amending the accepted question by extending it I'll upgrade my comment to an answer:

In the last term, the number of decimals you'll get depends mainly on the browser implementation so, depending on your targets you'll need to do some more research. Here you have an excellent post and a good starting point:

Browser Rounding and Fractional Pixels

Upvotes: 4

Related Questions