We have a need to generate number in vietnamese text.
This seems to be a goverment compliance requirement to have final numbers on an invoice to be presented in both numeric and litteral text form
So this is a POC to convert numbers in Long format to String Vietnamese text in java
# Compile and run the main() method
>javac NumToViet.java && java NumToViet
# Or use provided Makefile
> make
javac NumToViet.java
java NumToViet
[Passed] result: |0| - |không|
Group size is1
[Passed] result: |-1| - |âm một|
Group size is1
[Passed] result: |1| - |một|
Group size is1
[Failed] result: |một| expected |một trăm|
Group size is2
[Failed] result: |một| expected |một nghìn|
Group size is1
[Failed] result: |một| expected |mười|
Some test(s) failed!
rm -f *.class
If you are using this, please leave a comment inside Github Issue to let me know.
Any Pull Request to improve this would be more than welcome.
Project was written in
This library is just a Proof of Concepts. When use in production, there are several points that you can improve upon.
Apply Guava: Instead of using AtomicInteger
as a psuedo-index, you can use Streams.mapWithIndex()
from Guava to make your code cleaner
Recheck the logic of doShowZeroHundred()
: the logic was copied from the kotlin version of the code. Personally I think this logic is a bit clunky and could be shortened/simplified somehow. Given the exist test cases as baseline, you can modify this logic to make the code easier to understand.