fix rounding to 0 decimal places
This commit is contained in:
parent
12052b90e7
commit
8c83e1d482
3 changed files with 6 additions and 4 deletions
|
|
@ -253,6 +253,7 @@ Math.bound = function(val, min, max) {
|
|||
};
|
||||
|
||||
Number.prototype.round = function(digits) {
|
||||
if (digits === 0) return this.valueOf() | 0;
|
||||
const pow = Math.pow(10, digits || 3);
|
||||
return Math.round(this.valueOf() * pow) / pow;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -134,7 +134,9 @@ function inRange(value, min, max) {
|
|||
}
|
||||
|
||||
function round(v, zeros) {
|
||||
let pow = Math.pow(10, zeros || round_decimal_precision);
|
||||
const prec = zeros !== undefined ? zeros : round_decimal_precision;
|
||||
if (prec === 0) return v | 0;
|
||||
let pow = Math.pow(10, prec);
|
||||
return Math.round(v * pow) / pow;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ CAM.export = function(print, online) {
|
|||
function add0(val, opt) {
|
||||
let s = val.toString(),
|
||||
d = s.indexOf(".");
|
||||
if (d < 0) {
|
||||
if (d < 0 && decimals > 0) {
|
||||
return opt ? s : s + '.0';
|
||||
} else {
|
||||
return val.toFixed(decimals);
|
||||
|
|
@ -170,7 +170,6 @@ CAM.export = function(print, online) {
|
|||
newpos.x = util.round(newpos.x, decimals);
|
||||
newpos.y = util.round(newpos.y, decimals);
|
||||
newpos.z = util.round(newpos.z, decimals);
|
||||
// newpos.a = util.round(newpos.a || 0, decimals);
|
||||
|
||||
// on tool change
|
||||
let changeTool = out.tool != pos.t;
|
||||
|
|
@ -333,7 +332,7 @@ CAM.export = function(print, online) {
|
|||
if (map.Y) scale.y = map.Y;
|
||||
if (map.Z) scale.z = map.Z;
|
||||
if (map.DEC !== undefined) decimals = parseInt(map.DEC);
|
||||
console.log('scaling axes', scale);
|
||||
console.log('export scaling applied', map);
|
||||
} catch (e) {
|
||||
console.log('malformed scale directive', line);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue