round-money.ts 513 B

123456789101112131415161718
  1. import { getConfig } from '../config/config-helpers';
  2. import { MoneyStrategy } from '../config/entity/money-strategy';
  3. let moneyStrategy: MoneyStrategy;
  4. /**
  5. * @description
  6. * Rounds a monetary value according to the configured {@link MoneyStrategy}.
  7. *
  8. * @docsCategory money
  9. * @since 2.0.0
  10. */
  11. export function roundMoney(value: number, quantity = 1): number {
  12. if (!moneyStrategy) {
  13. moneyStrategy = getConfig().entityOptions.moneyStrategy;
  14. }
  15. return moneyStrategy.round(value, quantity);
  16. }