Clean up rounding code

This commit is contained in:
Hillel Coren 2017-11-06 12:50:19 +02:00
parent 2f6e8933f6
commit 31b445f725
2 changed files with 3 additions and 11 deletions

View File

@ -30,7 +30,7 @@ class ProductDatatable extends EntityDatatable
[
'cost',
function ($model) {
return Utils::formatMoney($model->cost);
return Utils::roundSignificant($model->cost);
},
],
[

View File

@ -866,13 +866,7 @@ function ItemModel(data) {
self.loadData = function(data) {
ko.mapping.fromJS(data, {}, this);
var precision = getPrecision(this.cost());
var cost = parseFloat(this.cost());
if (cost) {
this.cost(cost.toFixed(Math.max(2, precision)));
} else {
this.cost('');
}
this.cost(roundSignificant(this.cost(), true));
this.qty(roundSignificant(this.qty()));
}
@ -1025,9 +1019,7 @@ ko.bindingHandlers.productTypeahead = {
}
if (parseFloat(datum.cost)) {
if (! model.cost() || ! model.task_public_id()) {
var cost = roundSignificant(datum.cost);
var precision = getPrecision(cost);
model.cost(cost.toFixed(precision));
model.cost(roundSignificant(datum.cost, true));
}
}
if (!model.qty()) {