Javascript 尝试将动画设置为“时返回了错误的值”;柜台;

Javascript 尝试将动画设置为“时返回了错误的值”;柜台;,javascript,jquery,css-counter,Javascript,Jquery,Css Counter,每次API中的数据发生更改时,我都会使用以下方法,尝试使用“计数器”动画设置从API中获取的一些值: $('.count').each(function () { var $this = $(this); jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, { duration: 1000, easing: 'swing', s

每次API中的数据发生更改时,我都会使用以下方法,尝试使用“计数器”动画设置从API中获取的一些值:

 $('.count').each(function () {
        var $this = $(this);
        jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
            duration: 1000,
            easing: 'swing',
            step: function () {
                $this.text(this.Counter.toFixed(2));
            }
        });
    });
问题是API在下面的问题中给出的原始值是396718.760,所以格式化后的值应该是396718.76,但是当我用上面的函数设置动画时,它总是返回不同的值,正如您在这里看到的

那么如何通过返回正确的值来修复它呢?

尝试
Number.parseFloat(this.Counter).toFixed(2)
Try
Number.parseFloat(this.Counter).toFixed(2)