while comparing the generated reports of our old version of stimulsoft .NET and the new version of PHP that we recently purchased, I noticed some errors in the rounding of the two-digit digital numbers (in this case it is a percentage calculation but the same thing happens on the numeric).
To give an example, a figure like 0.36904761904761905 on the current PHP version is rounded (percentage) to 36.91 which is incorrect. In the old .NET version that we have on an old server (and the Designer), instead, it is correctly rounded (percentage) to 36.90.
Debugging thoroughly I discovered that the function js that does not round correctly is from the following (I have also highlighted the line that calculates the incorrect rounded decimals with an arrow, even if it is not the only point in the code where this type of calculation takes place):
Code: Select all
r.prototype.formatStr = function (t, e) {
var r = 0;
try {
r = e.toString().stimulsoft.toNumber()
} catch (t) {
return e.toString()
}
if (isNaN(r))
return e.toString();
var i = "";
r *= 100;
var n = r < 0,
o = Math.abs(r),
a = Math.floor(o),
s = 0;
if (0 == t.percentDecimalDigits)
a = Math.round(Math.abs(r));
else {
var l = Math.pow(10, t.percentDecimalDigits);
s = Math.round2(Math.round2(Math.round2(o - a, t.percentDecimalDigits + 1), t.percentDecimalDigits) * l), <-- this row calculate the decimal part and return 91 instead of 90 through Math.round2
s >= l && (a++, s = 0)
}
var u = a.toString();
if (t.percentGroupSizes[0] > 0 && this.useGroupSeparator) {
var c = u.length - t.percentGroupSizes[0];
while (c >= 0)
i = (c > 0 ? t.percentGroupSeparator : "") + u.substr(c, t.percentGroupSizes[0]) + i, c -= t.percentGroupSizes[0];
c < 0 && (i = u.substring(0, c + t.percentGroupSizes[0]) + i)
} else
i = u;
if (t.percentDecimalDigits > 0) {
u = s.toString();
while (u.length < t.percentDecimalDigits)
u = "0" + u;
i += t.percentDecimalSeparator + u
}
if (n)
switch (t.percentNegativePattern) {
case 0:
i = "-" + i + " " + t.percentSymbol;
break;
case 2:
i = "-" + t.percentSymbol + i;
break;
default:
i = "-" + i + t.percentSymbol;
break
}
else
switch (t.percentPositivePattern) {
case 0:
i = i + " " + t.percentSymbol;
break;
case 2:
i = t.percentSymbol + i;
break;
default:
i += t.percentSymbol;
break
}
return i
}
Thank you