Jump to content


Snap function - Issue

Moderator Tag
Go to solution Solved by GreenSock,

Recommended Posts

Hi there, I just came across a small issue related to the gsap.utils.snap function (gsap version 3.10.4):

gsap.utils.snap(0.01, 0.29); // Returns 0.28 instead of 0.29

I know that I could use other ways to get float number with 2 precision points but this function is very handy :)



Link to comment
Share on other sites

Great spot! Thanks for finding this. We'll look into it.


  • Thanks 1
Link to comment
Share on other sites

  • Solution

Ah, the joys of weird binary math issues. Check this out: 

console.log(0.29 * 100); // should be 29 but returns 28.999999999999996!



I've added some code to work around that issue in the next release which you can preview at https://assets.codepen.io/16327/gsap-latest-beta.min.js

  • Like 2
  • Haha 1
Link to comment
Share on other sites



It's time for the wat-duck again.

  • Haha 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.