Jump to Real's How-to Main page

Validate/Convert a number using the current Locale()

Depending on the International setting, numbers with comma as decimal separator may be permitted. The NumberFormat class can handle this based on the current Locale().
NumberFormat nf = NumberFormat.getInstance();
Number n = nf.parse(((TextField)theComponent).getText());
BigDecimal aDecimal = new BigDecimal(n.doubleValue());

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]