Skip to content

Default precision too low #1122

@glebm

Description

@glebm

Can the default Number#precision be changed to a higher value?

Because it's 5 now, and there is no standard way of setting precision across the forest of Sass environments (many not being Ruby), it causes lots of 1-px off errors, e.g. zurb/foundation#4336 and twbs/bootstrap-sass#409.

libsass also sets precision to 5 by default, same as ruby sass. Perhaps a higher value such as 10 is better as it would mean much less configuration pain for everyone?


ratio rounded error
2/3 66.66667% 0.33333333333E-5
1/6 16.66667% 0.33333333333E-5
3/7 42.85714% -0.28571428571E-5
7/11 63.63636% -0.36363636364E-5
7/31 22.58065% 0.48387096774E-5
p = 5
puts [2/3r, 1/6r, 3/7r, 7/11r, 7/31r].map { |r|
  v = r * 100
  rounded = BigDecimal.new(v, p + Math.log10(v).floor + 1)
  "| #{r} | #{rounded.to_s('F')}% | `#{(rounded - v).to_s('E')}` |" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions