details: https://code.openbravo.com/erp/devel/pi/rev/e9d73be9949d changeset: 26126:e9d73be9949d user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Thu Mar 05 10:15:41 2015 +0100 summary: Fixes issue 29113: Use setScale instead of round, and handle properly NaN
The BigDecimal.round function did not work as we expected [1]: new BigDecimal('0.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 0.15 (OK) new BigDecimal('1.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 1.1 (WRONG) new BigDecimal('10.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 10 (WRONG) To round the number to a specific amout of decimal digits, the setScale function should be used. new BigDecimal('0.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 0.15 (OK) new BigDecimal('1.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 1.15 (OK) new BigDecimal('10.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 10.15 (OK) Also, when the number provided in the first argument of the OB.Utilities.Number.roundJSNumber is not a number, the function returns NaN, as it used to do it before. [1] http://stackoverflow.com/a/13461270 diffstat: modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diffs (18 lines): diff -r 86a6b64eb747 -r e9d73be9949d modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js Wed Mar 04 18:51:22 2015 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js Thu Mar 05 10:15:41 2015 +0100 @@ -35,8 +35,12 @@ // Return: // * The rounded JS number OB.Utilities.Number.roundJSNumber = function (num, dec) { - var strNum = (isc.isA.String(num) ? num : String(num)); - return parseFloat(new BigDecimal(strNum).round(dec, BigDecimal.prototype.ROUND_HALF_UP)); + var strNum; + if (isNaN(num)) { + return NaN; + } + strNum = (isc.isA.String(num) ? num : String(num)); + return parseFloat(new BigDecimal(strNum).setScale(dec, BigDecimal.prototype.ROUND_HALF_UP)); }; // ** {{{ OB.Utilities.Number.OBMaskedToOBPlain }}} ** ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits