A JavaScript utility for converting numeric values into their corresponding textual representation in words. This includes both whole numbers and decimal parts, with support for currency formats.
- Converts numbers to words including handling of rupees and paise.
- Handles numbers with leading zeros and decimal values.
- Formats numbers in both singular and plural forms.
To use this code, simply include the script in your HTML file or import it into your JavaScript project.
<script src="path/to/numberToWords.js"></script>
<script>
var number = 1234.56;
console.log(numberToWords(number)); // Outputs: "One thousand two hundred thirty four rupees and fifty six paise only"
</script>
If using as a module, you can export the function from the script:
export function numberToWords(number) {
// Your function implementation
}
Then, import it into your project:
import { numberToWords } from './path/to/numberToWords.js';
var number = 1234.56;
console.log(numberToWords(number)); // Outputs: "One thousand two hundred thirty four rupees and fifty six paise only"
function numberToWords(number) {
// Function implementation here
}
number
: The numeric value to be converted. It should be a number, e.g.,1234.56
.
- A string representing the number in words, including the currency format. For example:
"One thousand two hundred thirty four rupees and fifty six paise only"
.
var number = 1234.56;
console.log(numberToWords(number));
// Output: "One thousand two hundred thirty four rupees and fifty six paise only"
var zeroNumber = 0.25;
console.log(numberToWords(zeroNumber));
// Output: "Twenty five paise only"
If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by various number-to-words utilities.
- Thanks to contributors and maintainers of open-source JavaScript libraries.