Skip to content

Amount

split

1.0.0

Splits an amount into equal parts (and distributes any remainder).

amount.split(/parts/);
  • Returns a AmountArray that supports fluent operations like .min() and .max()
  • Handles remainders by distributing the smallest currency unit (e.g., cents) across the initial parts
  • Automatically converts fractional parts into whole parts
  • Excepts dividing by zero or negative numbers, with proper error handling
  • Simple and intuitive API
  • Comprehensive testing
ArgTypeDefault ValueRequired
partsnumber-Yes

From an initial Amount instance, use the split() method using a number to divide the amount into equal parts.

import { amount } from '@inpulse-ui/utils';
const result = amount(100.00, 'USD').split(2);
console.log(result); // Results an AmountArray instance with 2 parts of 50 USD each

This method also “accepts” fractional parts - but it converts them into whole parts (e.g., 2.5 becomes 2) prior to splitting.

const result = amount(100.00, 'USD').split(2.5);
console.log(result); // Results an AmountArray instance with 2 parts of 40 USD and 1 part of 20 USD

It handles remainders by distributing the smallest currency unit (e.g., cents) across the initial parts.

const result = amount(100.00, 'USD').split(3);
console.log(result); // Results an AmountArray instance with parts of 33.34 USD, 33.33 USD, and 33.33 USD

Use split() when you want to:

  1. Split a bill among friends.

    const bill = amount(127.50, 'USD');
    const friends = 5;
    const portions = bill.split(friends); // [25.50, 25.50, 25.50, 25.50, 25.50]
  2. Split an amount into equal installments.

    const installments = payment.split(12); // 12 equal monthly payments
  3. Split an amount proportionally.

    const parts = amount.split(3); // [33.34, 33.33, 33.33] (handles remainder)

Please refer to the divide() method whenever you need to:

  • Perform mathematical division.
  • Calculate unit prices.
  • Reverse calculations (remove tax, etc.).
  • Get a single Amount result.

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.