Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pow = Math.pow(10, maxDecimals);
const rounded = Math.round(scalar * pow) / pow;
return rounded + ' ' + units;
};
};
qty = Qty('1.1234 m');
// same units, custom formatter => '1.12 m'
qty.format(configurableRoundingFormatter(2));
// convert to 'cm', custom formatter => '123.4 cm'
qty.format('cm', configurableRoundingFormatter(1));
Qty.formatter = configurableRoundingFormatter(2);
qty = Qty('1.1234 m');
qty.format(); // same units, current default formatter => '1.12 m'
Qty('37 tempC').to('tempF'); // => 98.6 tempF
const scalar: number = 42;
Qty('100 tempC').add('10 degC'); // 110 tempC
Qty('100 tempC').sub('10 degC'); // 90 tempC
Qty('100 tempC').add('50 tempC'); // throws error
Qty('100 tempC').sub('50 tempC'); // 50 degC
Qty('50 tempC').sub('100 tempC'); // -50 degC
Qty('100 tempC').mul(scalar); // 100*scalar tempC
Qty('100 tempC').div(scalar); // 100/scalar tempC
Qty('100 tempC').mul(qty); // throws error
Qty('100 tempC').div(qty); // throws error
afterEach(() => {
// Restore previous formatter
Qty.formatter = previousFormatter;
});
const pow = Math.pow(10, maxDecimals);
const rounded = Math.round(scalar * pow) / pow;
return rounded + ' ' + units;
};
};
qty = Qty('1.1234 m');
// same units, custom formatter => '1.12 m'
qty.format(configurableRoundingFormatter(2));
// convert to 'cm', custom formatter => '123.4 cm'
qty.format('cm', configurableRoundingFormatter(1));
Qty.formatter = configurableRoundingFormatter(2);
qty = Qty('1.1234 m');
qty.format(); // same units, current default formatter => '1.12 m'
Qty('37 tempC').to('tempF'); // => 98.6 tempF
const scalar: number = 42;
Qty('100 tempC').add('10 degC'); // 110 tempC
Qty('100 tempC').sub('10 degC'); // 90 tempC
Qty('100 tempC').add('50 tempC'); // throws error
Qty('100 tempC').sub('50 tempC'); // 50 degC
Qty('50 tempC').sub('100 tempC'); // -50 degC
Qty('100 tempC').mul(scalar); // 100*scalar tempC
Qty('100 tempC').div(scalar); // 100/scalar tempC
Qty('100 tempC').mul(qty); // throws error
Qty('100 tempC').div(qty); // throws error
beforeEach(() => {
previousFormatter = Qty.formatter;
Qty.formatter = roundingFormatter(3);
});
beforeEach(() => {
previousFormatter = Qty.formatter;
Qty.formatter = roundingFormatter(3);
});
beforeEach(() => {
previousFormatter = Qty.formatter;
Qty.formatter = roundingFormatter(3);
});