Java Hour Calculate getDoubleValue(String hours)

Here you can find the source of getDoubleValue(String hours)

Description

get Double Value

License

Open Source License

Declaration

public static double getDoubleValue(String hours) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2009 CodeGear and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import java.text.NumberFormat;
import java.text.ParseException;

import java.util.Locale;

public class Main {
    public static double getDoubleValue(String hours) {
        double doubleValue = 0.0;

        try {//  www  . j  av a2s. c o m
            doubleValue = getStandardHoursNumberFormat().parse(hours).doubleValue();
        } catch (ParseException e) {
            doubleValue = Double.valueOf(hours);
        }

        return doubleValue;
    }

    public static NumberFormat getStandardHoursNumberFormat() {
        return getHoursNumberFormat(Locale.US);
    }

    public static NumberFormat getHoursNumberFormat() {
        return getHoursNumberFormat(Locale.getDefault());
    }

    public static NumberFormat getHoursNumberFormat(Locale locale) {
        NumberFormat format = NumberFormat.getInstance(locale);
        format.setMaximumIntegerDigits(5);
        format.setMinimumFractionDigits(1);
        format.setMaximumFractionDigits(1);
        format.setGroupingUsed(false);
        format.setParseIntegerOnly(false);
        return format;
    }
}

Related

  1. getCurrHourDate()
  2. getDelayEndTime(int hour, String timezone)
  3. getDelayTime(int hour, String date)
  4. getDiffDateTime(int diff, int hours)
  5. getDiffHour(String startTime, String endTime)
  6. getExpiresDate(int hours)
  7. getTime(String dateStr, int hour, String timeZone)
  8. getTimestampFromDateHour2(String d)
  9. getTimeStringOfHourBefore(int hour)