Number to Words in Java
Read Time:1 Minute, 4 Second
Last Updated on April 19, 2024 by Hammad Rauf
This is related to an old post. This time I have translated it from C/C++ to Java and modified it a little bit. Now it takes as input additional parameters of currency-Note, currency-Coin and coin-Places. It is open sourced under Apache Software license 2.0. Source code can be found on Github.
Number-to-Words-in-Java is a program that takes as input a number and outputs the same number in English words form. It will be useful in situations like Bank Cheque printing. I was able to embed it in a Jaspersoft Studio Report, as shown in screen shots below.
Parameters Explained
Parameters for NumberToWords (in Java) | ||
---|---|---|
1 | Name | Number |
Data-Type | BigDecimal | |
Description | The Double or Float numeric value which needs to be converted into words. | |
2 | Name | currencyNote |
Data-Type | String | |
Description | The currency name that will appear in the output for the whole number part. | |
3 | Name | currencyCoin |
Data-Type | String | |
Description | The currency coin name that will appear in the output for the fractional number part. | |
4 | Name | coinPlaces |
Data-Type | Integer | |
Description | Number of digits in the coin output. For example for Dollar and Cents it should be 2. For some currency like Bahraini Dinar and Fills it will be 3. |
In use inside – Jaspersoft Studio Report
References
- The old post for C/C++ Function, https://andromedabay.ddns.net/number-to-words-recursive/, Date Accessed: March 28, 2024
- The old C/C++ Function, http://codepad.org/C29M1wUQ, Date Accessed: March 28, 2024
- Github repository for this (Java) Method, https://github.com/hexword-ca/NumberToWords, Date Accessed: March 28, 2024