How to use the js-quantities.formatter function in js-quantities

To help you get started, we’ve selected a few js-quantities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
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
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
afterEach(() => {
          // Restore previous formatter
          Qty.formatter = previousFormatter;
        });
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
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
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
beforeEach(() => {
          previousFormatter = Qty.formatter;
          Qty.formatter = roundingFormatter(3);
        });
github DefinitelyTyped / DefinitelyTyped / types / js-quantities / js-quantities-tests.ts View on Github external
beforeEach(() => {
          previousFormatter = Qty.formatter;
          Qty.formatter = roundingFormatter(3);
        });
github DefinitelyTyped / DefinitelyTyped / js-quantities / js-quantities-tests.ts View on Github external
beforeEach(() => {
          previousFormatter = Qty.formatter;
          Qty.formatter = roundingFormatter(3);
        });