2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.fronius.internal.math;
16 * Helper class for unit conversions
18 * @author Thomas Rokohl - Initial contribution
21 public class KilowattConverter {
23 public static double getConvertFactor(String fromUnit, String toUnit) {
24 String adjustedFromUnit = fromUnit.replace("Wh", "");
25 String adjustedtoUnit = toUnit.replace("Wh", "");
26 return SiPrefixFactors.getFactorToBaseUnit(adjustedFromUnit) * 1
27 / SiPrefixFactors.getFactorToBaseUnit(adjustedtoUnit);
30 public static double convertTo(double value, String fromUnit, String toUnit) {
31 return value * getConvertFactor(fromUnit, toUnit);