Documentation

API reference

Complete reference for all 11 exported functions. Try them live in the playground.

Installation

bash
npm install moneyutils-in

Currency

Format INR amounts and convert between rupees and paise.

formatINR

formatINR(amount: number, options?: FormatINROptions): string

Formats a number as Indian Rupees with lakh-style grouping. Options: decimals (default 2), symbol (default true).

Returns: Formatted INR string

typescript
formatINR(125000);
// "₹1,25,000.00"

formatINR(125000, { decimals: 0, symbol: false });
// "1,25,000"

rupeesToPaise

rupeesToPaise(rupees: number): number

Converts rupees to paise as an integer. Useful for payment gateways that expect amounts in paise.

Returns: Integer paise value

typescript
rupeesToPaise(499.99);
// 49999

paiseToRupees

paiseToRupees(paise: number): number

Converts paise back to rupees.

Returns: Rupees as a number

typescript
paiseToRupees(49999);
// 499.99

GST

Add or remove GST with CGST/SGST for intra-state or IGST for inter-state transactions. Transaction type defaults to INTRA_STATE.

addGST

addGST(amount: number, gstRate: number, transactionType?: GSTTransactionType): GSTResult

Adds GST to a taxable amount. Intra-state splits tax into CGST and SGST; inter-state uses IGST.

Returns: GSTResult — taxableAmount, cgst, sgst, igst, totalTax, totalAmount

typescript
addGST(1000, 18);
// { taxableAmount: 1000, gstRate: 18, cgst: 90, sgst: 90, igst: 0, totalTax: 180, totalAmount: 1180 }

addGST(1000, 18, "INTER_STATE");
// { taxableAmount: 1000, gstRate: 18, cgst: 0, sgst: 0, igst: 180, totalTax: 180, totalAmount: 1180 }

removeGST

removeGST(inclusiveAmount: number, gstRate: number, transactionType?: GSTTransactionType): GSTResult

Extracts the taxable base and tax components from a GST-inclusive price.

Returns: GSTResult

typescript
removeGST(1180, 18);
// { taxableAmount: 1000, gstRate: 18, cgst: 90, sgst: 90, igst: 0, totalTax: 180, totalAmount: 1180 }

Discounts

Percentage and fixed-amount discount calculations.

calculatePercentageDiscount

calculatePercentageDiscount(amount: number, percentage: number): DiscountResult

Applies a percentage discount and returns original, discount, and final amounts.

Returns: DiscountResult

typescript
calculatePercentageDiscount(2000, 15);
// { originalAmount: 2000, discountAmount: 300, finalAmount: 1700, percentage: 15 }

calculateFixedDiscount

calculateFixedDiscount(amount: number, discount: number): FixedDiscountResult

Applies a fixed rupee discount to an amount.

Returns: FixedDiscountResult

typescript
calculateFixedDiscount(2000, 300);
// { originalAmount: 2000, discountAmount: 300, finalAmount: 1700 }

Percentage

calculatePercentage

calculatePercentage(amount: number, percentage: number): number

Returns a percentage of the given amount.

Returns: Calculated percentage value

typescript
calculatePercentage(5000, 12);
// 600

Fees

Platform and convenience fee calculations.

calculatePercentageFee

calculatePercentageFee(amount: number, feeRate: number): PercentageFeeResult

Calculates a percentage-based platform or convenience fee on a base amount.

Returns: PercentageFeeResult

typescript
calculatePercentageFee(1000, 2.5);
// { baseAmount: 1000, feeRate: 2.5, feeAmount: 25, totalAmount: 1025 }

Commission

Marketplace commission and net payout calculations.

calculateCommission

calculateCommission(amount: number, commissionRate: number): CommissionResult

Calculates marketplace commission and net payout from a gross amount.

Returns: CommissionResult

typescript
calculateCommission(5000, 12);
// { amount: 5000, commissionRate: 12, commissionAmount: 600, netAmount: 4400 }

Order Total

Full cart calculation with line items, optional percentage or fixed discount, named fees, and GST.

calculateOrderTotal

calculateOrderTotal(input: CalculateOrderTotalInput): OrderTotalResult

Computes full cart totals: subtotal, discount, fees, tax, and grand total from line items.

Returns: OrderTotalResult

typescript
calculateOrderTotal({
  items: [
    { price: 999, quantity: 2 },
    { price: 2499, quantity: 1 },
  ],
  discount: { type: "percentage", value: 10 },
  fees: [{ name: "Delivery", amount: 50 }],
  tax: { rate: 18 },
});
// {
//   subtotal: 4497,
//   discountAmount: 449.7,
//   subtotalAfterDiscount: 4047.3,
//   feeTotal: 50,
//   taxableAmount: 4097.3,
//   taxAmount: 737.51,
//   grandTotal: 4834.81
// }

CalculateOrderTotalInput

  • items — array of { price, quantity }
  • discount? — { type: "percentage" | "fixed", value: number }
  • fees? — array of { name, amount }
  • tax? — { rate: number }

TypeScript Exports

All functions and result types are fully typed.

typescript
import {
  formatINR,
  rupeesToPaise,
  paiseToRupees,
  addGST,
  removeGST,
  calculatePercentageDiscount,
  calculateFixedDiscount,
  calculatePercentage,
  calculatePercentageFee,
  calculateCommission,
  calculateOrderTotal,
} from "moneyutils-in";

import type {
  FormatINROptions,
  DiscountResult,
  FixedDiscountResult,
  GSTResult,
  GSTTransactionType,
  PercentageFeeResult,
  CommissionResult,
  OrderItem,
  OrderFee,
  OrderDiscount,
  OrderTax,
  CalculateOrderTotalInput,
  OrderTotalResult,
} from "moneyutils-in";

Disclaimer

GST and tax utilities perform calculations based on the values provided by the developer. They do not determine the legally applicable tax rate or tax treatment for a transaction.

Money Utils IN

TypeScript-first money utilities for INR formatting, GST, discounts, fees, commissions, and order totals for Indian e-commerce and booking apps.

© 2026 Money Utils IN