Amount
split
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Splits an amount into equal parts (and distributes any remainder).
amount.split(/parts/);Features
Section titled “Features”- Returns a
AmountArraythat 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
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
parts | number | - | 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 eachThis 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 USDIt 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 USDExamples
Section titled “Examples”Use split() when you want to:
-
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] -
Split an amount into equal installments.
const installments = payment.split(12); // 12 equal monthly payments -
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.
Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.