Giter Site home page Giter Site logo

sluongng / java-num-2-vietnamese Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 4.0 27 KB

a library to convert numeric value to String of words in Vietnamese

Java 99.25% Makefile 0.75%
number-to-words number-to-text vietnamese vietnam vietnamese-language invoice invoicing

java-num-2-vietnamese's Introduction

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.

java-num-2-vietnamese's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

java-num-2-vietnamese's Issues

[Concern]- issue with big number

testCase.put(101_002_101_000_000_000L,"Một trăm lẻ một triệu tỷ không trăm lẻ hai nghìn tỷ một trăm lẻ một tỷ");

Theo mình thì số trên đọc như vậy chưa chuẩn, có thể sữa như vậy thì đúng hơn:
"Một trăm lẻ một triệu, không trăm lẻ hai nghìn, một trăm lẻ một tỷ"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.