Java Date Format As fmtNumStringToDouble(String s)

Here you can find the source of fmtNumStringToDouble(String s)

Description

fmt Num String To Double

License

Open Source License

Declaration

public static double fmtNumStringToDouble(String s) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

import java.text.ParseException;

public class Main {
    public static double fmtNumStringToDouble(String s) {
        double d = 0.0;
        if (s == null || s.trim().length() == 0)
            return 0.0;
        DecimalFormat DF_4_DP = new DecimalFormat("###,##0.0000");
        DecimalFormat DF_2_DP = new DecimalFormat("###,##0.00");
        //first try parsing as currency
        DecimalFormat df = DF_2_DP;
        try {//ww  w .  j a  v  a 2 s .c o m
            d = df.parse(s).doubleValue();
            return d;
        }
        //if that doesn't work, try the decimal formatter
        catch (ParseException pe) {
        }
        df = DF_4_DP;
        try {
            d = df.parse(s).doubleValue();
        }
        //throw an exception
        catch (ParseException pe) {
            d = 0.0;
        }
        return d;
    }
}

Related

  1. fmtBdToString(BigDecimal bd, DecimalFormat df)
  2. fmtDate(Date date)
  3. fmtDate(Date date)
  4. fmtDateTime(final Date dateTime, final String simpleDateTimeFormat)
  5. fmtMsg(final String fmt, final String arg)
  6. fmtTime(Date time)
  7. formatDateAccordingToSessionDuration(Calendar cal, int sessionDuration, int offset)
  8. formatDateAppello(Date data)
  9. formatDateAsFileSystemName()