2.0.0 • Published 4 months ago
int2words v2.0.0
int2words
Convert integers into words.
Features and limitations:
- Languages: English and Japanese.
- Integer range: 0 → 253–1.
- While 64-bit floating-point numbers technically support numbers up to approximately 1.8 × 10308, there is a significant loss of precision. 253–1 is the largest integer with no loss of precision.
Install
npm install int2words
Usage
import { int2en, int2ja } from 'int2words';
console.log(int2en(321)); // "three hundred twenty-one"
console.log(int2ja(321)); // "三百二十一"
console.log(int2en(-1)); // Invalid input: ""
/**
* Optionally throw an error.
*/
try {
int2en(-1, { throwError: true });
} catch (error) {
if (error instanceof CoercionError) {
console.error(error); // "CoercionError: Expected a positive integer."
}
throw error;
}
const { int2en, int2jw } = require('int2words');
No Bundler Install and Usage
To use in browsers directly and without bundlers.
- Save
int2words.min.js
to your project. - Add
<script src="int2words.min.js">
in your HTML file. - The library is now available globally through the
int2words
object.
console.log(int2words.int2en(321)); // "three hundred twenty-one"
Changelog
v2.0.0 (2025-3-14)
Change name and modernize.
v1.2.7 (2016-5-4)
Acknowledgments
- Originally a modification from http://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript.
License
This project is licensed under the GNU General Public License (GPL).
2.0.0
4 months ago