1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Fix for negative rounding

This commit is contained in:
Hillel Coren 2017-08-08 21:03:49 +03:00
parent 5eaa938809
commit 17ecf8ecde
4 changed files with 22 additions and 8 deletions

View File

@ -139,7 +139,7 @@ class CheckData extends Command
private function checkInvoices()
{
if (! env('PHANTOMJS_BIN_PATH')) {
if (! env('PHANTOMJS_BIN_PATH') || ! Utils::isNinjaProd()) {
return;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1043,16 +1043,30 @@ function toggleDatePicker(field) {
$('#'+field).datepicker('show');
}
function roundToTwo(num, toString) {
var val = +(Math.round(num + "e+2") + "e-2");
function roundToTwo(number, toString) {
var val = roundToPrecision(number, 2);
return toString ? val.toFixed(2) : (val || 0);
}
function roundToFour(num, toString) {
var val = +(Math.round(num + "e+4") + "e-4");
function roundToFour(number, toString) {
var val = roundToPrecision(number, 4);
return toString ? val.toFixed(4) : (val || 0);
}
// https://stackoverflow.com/a/18358056/497368
function roundToPrecision(number, precision) {
// prevent negative numbers from rounding to 0
var isNegative = number < 0;
if (isNegative) {
number = number * -1;
}
number = +(Math.round(number + "e+"+ precision) + "e-" + precision);
if (isNegative) {
number = number * -1;
}
return number;
}
function truncate(str, length) {
return (str && str.length > length) ? (str.substr(0, length-1) + '...') : str;
}