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
- Not supporting decimal. Vietnamese currency is most common to be used in "thousands" unit. E.g. 500 VND is the smallest paper bill, 1000 or 2000 VND is the most common bill still in circulation at the time of writting this. It does not make a lot of sense to support decimal places since most of the calculation result will have left over numbers placed within the 1000 VND margin. Its common in Vietnam to accept that anything smaller than 1 VND to be nelegible.
# 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
- NeoVim
- Coc.nvim
- Coc-Java
- Eclipse Java LSP https://github.com/eclipse/eclipse.jdt.ls/
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 useStreams.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.