Package br.com.colegio.util

Source Code of br.com.colegio.util.NumberParser

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();
    }
  }
}
TOP

Related Classes of br.com.colegio.util.NumberParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.