Skip to content

Amount

toString

1.0.0

Converts an amount to its string representation by calling the format() method internally. This provides a formatted currency string suitable for display.

amount.toString();
  • Returns a formatted currency string
  • Uses the format() method internally
  • Automatically formats according to currency conventions
  • Useful for string concatenation and display
  • Handles different currencies appropriately
  • Simple and intuitive API
  • No side effects - read-only operation
  • Comprehensive testing
ArgTypeDefault ValueRequired
No arguments required

From an Amount instance, use the toString() method to get a formatted string representation.

import { amount } from '@inpulse-ui/utils';
const myAmount = amount(123.45, 'USD');
const stringValue = myAmount.toString();
console.log(stringValue); // "$123.45"

Works with different currencies:

const usdAmount = amount(99.99, 'USD');
const eurAmount = amount(85.50, 'EUR');
const gbpAmount = amount(75.25, 'GBP');
console.log(usdAmount.toString()); // "$99.99"
console.log(eurAmount.toString()); // "€85.50"
console.log(gbpAmount.toString()); // "£75.25"

Handles negative values:

const negativeAmount = amount(-25.50, 'USD');
const stringValue = negativeAmount.toString();
console.log(stringValue); // "-$25.50"

Zero values:

const zeroAmount = amount(0, 'EUR');
const stringValue = zeroAmount.toString();
console.log(stringValue); // "€0.00"

String concatenation and templating:

const price = amount(299.99, 'USD');
const tax = amount(24.00, 'USD');
const message = `Price: ${price.toString()}, Tax: ${tax.toString()}`;
console.log(message); // "Price: $299.99, Tax: $24.00"
// Or using template literals directly (toString() is called automatically)
const autoMessage = `Total: ${price.add(tax)}`;
console.log(autoMessage); // "Total: $323.99"

Display in user interfaces:

const orderAmount = amount(149.95, 'USD');
// Set text content in DOM
document.getElementById('order-total').textContent = orderAmount.toString();
// Or create display components
const orderSummary = {
subtotal: amount(130.00, 'USD').toString(),
shipping: amount(9.95, 'USD').toString(),
tax: amount(10.00, 'USD').toString(),
total: amount(149.95, 'USD').toString()
};
console.log(orderSummary);
// {
// subtotal: "$130.00",
// shipping: "$9.95",
// tax: "$10.00",
// total: "$149.95"
// }

Logging and debugging:

const amounts = [
amount(100, 'USD'),
amount(200, 'EUR'),
amount(150, 'GBP')
];
amounts.forEach((amt, index) => {
console.log(`Amount ${index}: ${amt.toString()}`);
});
// Amount 0: $100.00
// Amount 1: €200.00
// Amount 2: £150.00

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.