Skip to content

Number Rounding Precision #1512

@tonyvranic

Description

@tonyvranic

Hey, I'm writing a Sass interpreter and I found some inconsistencies regarding rounding numbers in practice and the rules in the docs.
My version of Sass is: 1.94.1

The examples in the docs state:

@debug 0.012345678912345; // 0.0123456789
@debug 0.01234567891 == 0.01234567899; // true
@debug 1.00000000009; // 1
@debug 0.99999999991; // 1

But in practice these examples return the following:

@debug 0.012345678912345;  // 0.012345678912345
@debug 0.01234567891 == 0.01234567899; // false
@debug 1.00000000009; // 1.00000000009
@debug 0.99999999991; // 0.99999999991

Numbers

Using @debug I couldn't really determine when the rounding even happens, but here are some tests:

// Rounds up to 18 decimal places - The last digit actually changed here on it's own for some reason?
@debug 0.012345678912345678; // 0.012345678912345679
// Doesn't round
@debug 0.000000000000000000000000008; // 0.000000000000000000000000008

When writing SCSS, rounding works by rounding to 10 decimal places:

padding: 0.00000000004px; // padding: 0px;
padding: 0.00000000005px; // padding: 0.0000000001px;

Equations

As for equations, they seem to round to 11 decimal places, instead of just going to 10:

@debug 0.000000000014 == 0.000000000014;  // true
@debug 0.000000000014 == 0.000000000015;  // false

Integers

And finally rounding to ints:

@debug 1.000000000004 == 1;  // true
@debug 1.000000000005 == 1;  // false

@debug 0.999999999994 == 1;  // false
@debug 0.999999999995 == 1;  // true

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions