Skip to content

sluongng/java-num-2-vietnamese

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

java-num-2-vietnamese

Purpose

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

Out of Scope

  • 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.

Testing

# 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

Support

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 setup

Project was written in

Improvement

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.

Releases

No releases published

Packages

No packages published