Our pure JavaScript Scheduler component


Post by KAB »

Hi

I am Integration bryntum scheduler in an existing application: Odoo

The scheduler fixes the Polyfill bug in libs/Common/helper/DomHelper.js by overwriting the Number prototype.
However Odoo depends on this function and now there are rounding errors in the Odoo frontend.
For example product price of 1.5 becomes 1.51 because of the patched call of toFixed.

Do you see a workaround for this problem? Any suggestion/tip would be really helpful.

To test please copy the following code snippet of the scheduler in the js console and then execute






console.log("before patch "+(1.5).toFixed(2));
if (1.005.toFixed(2) !== '1.01') {
  var numberPrototype = Number.prototype,
      toFixed = numberPrototype.toFixed;

  numberPrototype.toFixed = function (fractionDigits) {
    var split = this.toString().split('.'),
        number = +(!split[1] ? split[0] : split.join('.') + '1');
    return toFixed.call(number, fractionDigits);
  };
  }
console.log("after patch "+(1.5).toFixed(2));
Last edited by KAB on Fri Mar 15, 2019 8:47 pm, edited 1 time in total.

Post by mats »

Which version of Scheduler? Try latest nightly build?

Post by KAB »

I downloaded 1.2.5, I will try with nightly latest build

Post by KAB »

The problem still exist with latest version.
Please just copy&paste the snippet in a fresh JS console (the patched function is taken from lib/common/helper/Domhelper.js)
console.log("before patch "+(1.5).toFixed(2));
if ((1.005).toFixed(2) !== '1.01') {
    const numberPrototype = Number.prototype,
        toFixed = numberPrototype.toFixed;

    numberPrototype.toFixed = function(fractionDigits) {
        const split = this.toString().split('.'),
            number = +(!split[1] ? split[0] : split.join('.') + '1');

        return toFixed.call(number, fractionDigits);
    };
}
console.log("after patch "+(1.5).toFixed(2));

Post by johan.isaksson »

Hi,

We have decided to remove our polyfill and use other means to achieve what we needed it for. It will be gone in the next major release (2.0). Ticket to track it here: https://app.assembla.com/spaces/bryntum/tickets/7823
Best regards,
Johan Isaksson

Post by KAB »

Hi

Thanks for the quick update.
Is there a backport of the bugfix to the latest scheduler version? My client cannot wait until the major 2.0 release as the scheduler is already used in production and this bug is blocking.

Thank you and regards
KA

Post by pmiklashevich »

Hello,

To get it fixed just remove our polyfill from lib/Common/helper/DomHelper.js:
// Polyfill toFixed rounding bug
if ((1.005).toFixed(2) !== '1.01') {
    const numberPrototype = Number.prototype,
        toFixed = numberPrototype.toFixed;

    numberPrototype.toFixed = function(fractionDigits) {
        const split = this.toString().split('.'),
            number = +(!split[1] ? split[0] : split.join('.') + '1');

        return toFixed.call(number, fractionDigits);
    };
}
Best regards,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by KAB »

OK this seems to work. Thanks for the quick bugfix/workaround.

Post Reply