Programming Functions for Number-Word Conversion

Explore our collection of ready-to-use functions for converting numbers to words across multiple programming languages. These implementations handle standard number-to-word conversion, ordinal forms, and currency formatting to meet your development needs.

JavaScript
Python
Java
C#
PHP

Core Functions Available in All Languages

numberToWords(number)

Converts a number to its word representation (e.g., 123 → "one hundred twenty-three")

numberToOrdinalWords(number)

Converts a number to its ordinal form (e.g., 21 → "twenty-first")

numberToCurrencyWords(amount, currencyName, subunitName)

Formats a number as currency words for checks and financial documents (e.g., 1234.56 → "One thousand two hundred thirty-four dollars and fifty-six cents")

Implementation Features

  • Support for numbers from zero to trillions
  • Proper handling of negative numbers
  • Correct hyphenation for compound numbers (e.g., twenty-one)
  • Special case handling for ordinal forms (first, second, third, etc.)
  • Customizable currency and subunit names
  • Proper pluralization of currency units

Download the Code

Each implementation includes comprehensive comments and follows best practices for the respective language. Download the full code with examples:

JavaScript (.js) Python (.py) Java (.java) C# (.cs) PHP (.php)

Common Usage Example

// Convert a simple number to words
numberToWords(42567);  
// Result: "forty-two thousand five hundred sixty-seven"

// Format a check amount
numberToCurrencyWords(1250.75);  
// Result: "One thousand two hundred fifty dollars and seventy-five cents"

// Create an ordinal number
numberToOrdinalWords(23);  
// Result: "twenty-third"

For implementation details, algorithm explanations, and advanced usage scenarios, please download the full code examples above or visit our API Documentation page.