Android Double to String Convert doubleToText(final double d)

Here you can find the source of doubleToText(final double d)

Description

double To Text

Declaration

public static String doubleToText(final double d) 

Method Source Code

//package com.java2s;

public class Main {
    public static String doubleToText(final double d) {
        final int hours = Double.valueOf(d).intValue();
        final int minutes = Double.valueOf(d * 10 - hours * 10).intValue() * 6;

        final String hoursWord = getHoursWord(hours);
        final String minutesWord = getMinutessWord(minutes);

        return hours + " " + hoursWord + ", " + minutes + " " + minutesWord;
    }/*from   ww  w.  jav a  2 s .  c  o m*/

    private static String getHoursWord(final int hours) {
        String hoursWord;
        if (hours == 1 || hours == 0) {
            hoursWord = "hour";
        } else {
            hoursWord = "hours";
        }
        return hoursWord;
    }

    private static String getMinutessWord(final int minutes) {
        String minutesWord;
        if (minutes == 1 || minutes == 0) {
            minutesWord = "minute";
        } else {
            minutesWord = "minutes";
        }
        return minutesWord;
    }
}