Skip to content

fix: do not round non-zero values down to zero#264

Open
dkryaklin wants to merge 1 commit into
postcss:masterfrom
dkryaklin:fix/round-non-zero-to-zero
Open

fix: do not round non-zero values down to zero#264
dkryaklin wants to merge 1 commit into
postcss:masterfrom
dkryaklin:fix/round-non-zero-to-zero

Conversation

@dkryaklin

Copy link
Copy Markdown
Contributor

No description provided.

@ludofischer ludofischer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the goal of this change? Right now I don't understand what's going on.

Comment thread test/index.js

test(
'should not round a non-zero value down to zero',
testValue('calc(1/1000000)', '0.00001')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does dividing 1 by one million give 1e-06 instead of 1e-05? I guess it's related to the precision being 5 decimal digits, but I would appreciate some explanation or a link to the spec.

Comment thread src/lib/serialize.js
}
const m = Math.pow(10, prec);
return Math.round(v * m) / m;
const rounded = Math.round(v * m) / m;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some comment about explaining why the code is doing this or nobody will understand it in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants