Jump to content
Search Community

Rounding entering values

Nalex test
Moderator Tag

Recommended Posts

Hey. I started to use gsap animation few weeks ago and create some functions, but i dont know, how i could round values to prevent float values during animations.

 

My code is working, but is very bad code, i think :)

 

 

function prettify(num) {
            let n = num.toString();
            return n.replace(/(\d{1,3}(?=(?:\d\d\d)+(?!\d)))/g, "$1" + ' ');
        }

  // transform digits like 99000 in digits 99 000 (adding spaces)


const total_total = Math.round(((((type * ppl * days * hours) * ak) * tax) + total_cord) / 10) * 10;
  // my value

 

 

TweenLite.to(total_result, 0.5, {innerHTML: prettify(total_total),  roundProps: 'innerHTML', ease: SteppedEase.config(10), onComplete: function(){
    $('#total_result').val(total_total)}})
}


  // my animation

 

So, to round my values i need now:

 

1. round value in 10 like (/ 10) * 10)
2. i need to add Stteped ease with config 10

3. i need to add roundProps.

 

Please help me :)

How i can do it easily to prevent float digits during animation. 

Thank you.

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.
×
×
  • Create New...