Skip to content

Commit 2e43755

Browse files
committed
prove we need Math.round
1 parent 95ee4a4 commit 2e43755

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

packages/tailwindcss/src/constant-fold-declaration.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ it('should not constant fold when dividing by `0`', () => {
131131
it('should not constant fold when a computation has a high-precision result', () => {
132132
expect(constantFoldDeclaration('calc(100% / 3.5)')).toBe('calc(100% / 3.5)')
133133
})
134+
135+
it('should constant fold division results with floating-point error after scaling', () => {
136+
expect(constantFoldDeclaration('calc(29% / 100)')).toBe('0.29%')
137+
})

packages/tailwindcss/src/constant-fold-declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export function constantFoldDeclarationAst(
293293
// E.g. 100% / 3.5 = 28.571428571428573%, which is correct but not
294294
// as user friendly. Especially when going from
295295
// `w-[calc(100%/3.5)]` → `w-[28.571428571428573%]`
296-
if (Math.floor(computed * 100) / 100 !== computed) {
296+
if (Math.round(computed * 100) / 100 !== computed) {
297297
break
298298
}
299299

0 commit comments

Comments
 (0)