Java Duration to durationToFloat(Duration duration)

Here you can find the source of durationToFloat(Duration duration)

Description

duration To Float

License

BSD License

Declaration

public static float durationToFloat(Duration duration) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.math.BigDecimal;
import java.time.Duration;

public class Main {
    public static float durationToFloat(Duration duration) {
        Float hours = Float.valueOf(duration.toMinutes()) / 60;
        return round(hours, 2);
    }/*from  w w  w.jav  a 2 s .c  o  m*/

    public static float round(float d, int decimalPlace) {
        BigDecimal bd = new BigDecimal(Float.toString(d));
        bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
        return bd.floatValue();
    }
}

Related

  1. durationToString(Duration d)
  2. toDuration(Long unixTime)
  3. toDuration(String durationString)
  4. toMicro(Duration duration)