Java BigInteger Power powerToEnergy(BigInteger power, Integer ptuDuration)

Here you can find the source of powerToEnergy(BigInteger power, Integer ptuDuration)

Description

Transforms a power (Watt) of a PTU to an energy (Watt hour).

License

Apache License

Parameter

Parameter Description
power BigInteger power expressed in Watts
ptuDuration PTU duration

Return

the energy expressed in Watt hours

Declaration

public static BigInteger powerToEnergy(BigInteger power, Integer ptuDuration) 

Method Source Code


//package com.java2s;
/*/*  www.j av  a 2 s.  c  o  m*/
 * Copyright 2015-2016 USEF Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import org.joda.time.Hours;

public class Main {
    private static final int DECIMAL_PRECISION = 5;

    /**
     * Transforms a power (Watt) of a PTU to an energy (Watt hour).
     *
     * @param power       {@link BigInteger} power expressed in Watts
     * @param ptuDuration PTU duration
     * @return the energy expressed in Watt hours
     */
    public static BigInteger powerToEnergy(BigInteger power, Integer ptuDuration) {
        BigDecimal hoursPerPtu = new BigDecimal(Hours.ONE.toStandardMinutes().getMinutes())
                .divide(new BigDecimal(ptuDuration), DECIMAL_PRECISION, RoundingMode.HALF_UP);
        return new BigDecimal(power).divide(hoursPerPtu, DECIMAL_PRECISION, RoundingMode.HALF_UP).toBigInteger();
    }
}

Related

  1. pow(BigInteger base, BigInteger exponent)
  2. Power(BigInteger base, int exp)