Trouble understanding rounding when the next digit is after round precision is a #5?

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • decimal

    Arbitrary-precision fixed-point decimal numbers in Go

  • Try it in JS with console.log(4.225 * 100);, you'll see the same unexpected result. Depending on your needs, it's actually fine to just be off by some amount. If it does really matter, then use an arbitrary precision library like https://github.com/shopspring/decimal to get the results you need.

  • 0.30000000000000004

    Floating Point Math Examples

  • Start by understanding that the "4.225", "4.224", ... in your code are not "floats" in the sense if IEEE float64: They are decimal (!) and might not be representable in float64. See e.g. https://0.30000000000000004.com/

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts