1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Clean up JS rounding code

This commit is contained in:
Hillel Coren 2017-11-06 10:08:23 +02:00
parent fed2e57891
commit ee917ba95a
4 changed files with 12 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -612,8 +612,8 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
custom_value1 = processVariables(item.custom_value1);
custom_value2 = processVariables(item.custom_value2);
}
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost)) * roundSignificant(NINJA.parseFloat(item.qty));
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty));
if (account.include_item_taxes_inline == '1') {
var taxAmount1 = 0;
var taxAmount2 = 0;

View File

@ -1060,20 +1060,20 @@ function getPrecision(number) {
}
}
function roundSignificant(number) {
function roundSignificant(number, toString) {
var precision = getPrecision(number);
var value = roundToPrecision(number, precision);
return isNaN(value) ? 0 : value;
var val = roundToPrecision(number, precision) || 0;
return toString ? val.toFixed(precision) : val;
}
function roundToTwo(number, toString) {
var val = roundToPrecision(number, 2);
return toString ? val.toFixed(2) : (val || 0);
var val = roundToPrecision(number, 2) || 0;
return toString ? val.toFixed(2) : val;
}
function roundToFour(number, toString) {
var val = roundToPrecision(number, 4);
return toString ? val.toFixed(4) : (val || 0);
var val = roundToPrecision(number, 4) || 0;
return toString ? val.toFixed(4) : val;
}
// https://stackoverflow.com/a/18358056/497368