package br.com.colegio.util;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParseException;
import java.util.Locale;
public class NumberParser
{
private static final String FLOAT = "(-?\\d+(?:\\.[0-9]+)?(?:[Ee]\\-?[0-9]+)?)";
private static final String INT = "([0-9]+)";
public static boolean isFloat(String s)
{
return (s.matches(FLOAT));
}
public static boolean isInt(String s)
{
return (s.matches(INT));
}
public static String format(double n) throws ParseException
{
return (new DecimalFormat("#,##0.00", new DecimalFormatSymbols(new Locale("pt","BR")))).format(n);
}
public static void main(String[] args)
{
try
{
System.out.println(NumberParser.format(3598.7699999999995));
}
catch (ParseException e)
{
e.printStackTrace();
}
}
}