Writing-out numbers in mandarin till 19999 algorithm
Your algorithm have to handle 0 between first and last digits as well. Insert 零 for those cases.
For example,

10003 should be 一萬零三.
10301 should be 一萬零三百零一.
30028 should be 三萬零二十八.
41009 should be 四萬一千零九.