Created
January 15, 2014 10:48
-
-
Save namuan/8434231 to your computer and use it in GitHub Desktop.
Convert number to words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes( | |
@Grab(group='com.ibm.icu', module='icu4j', version='52.1') | |
) | |
import com.ibm.icu.text.* | |
import java.util.Locale | |
import com.ibm.icu.text.RuleBasedNumberFormat | |
public String spellOut(num) { | |
NumberFormat formatter = new RuleBasedNumberFormat(RuleBasedNumberFormat.SPELLOUT) | |
String result = formatter.format(num) | |
result | |
} | |
assert "one hundred" == spellOut(100) | |
assert "one hundred one" == spellOut(101) | |
assert "two thousand seven hundred eighteen point two eight" == spellOut(2718.28) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment