]> git.basschouten.com Git - openhab-addons.git/blob
dab22b20e71209f5034b24626dbfcb90b6a80620
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.fronius.internal.math;
14
15 /**
16  * Helper class for unit conversions
17  *
18  * @author Thomas Rokohl - Initial contribution
19  *
20  */
21 public class SiPrefixFactors {
22
23     /**
24      * return the relative factor to the base unit
25      * k == 1000, M = 1000000 ...
26      * Not completely!!! Rank from n to T
27      *
28      * @param prefix of the unit
29      * @return relative factor to the base unit
30      */
31
32     public static double getFactorToBaseUnit(String prefix) {
33         if (prefix.isEmpty()) {
34             return 1;
35         }
36         switch (prefix) {
37             case "T":
38                 return 1000000000000d;
39             case "G":
40                 return 1000000000;
41             case "M":
42                 return 1000000;
43             case "k":
44                 return 1000;
45             case "h":
46                 return 100;
47             case "da":
48                 return 10;
49             case "d":
50                 return 0.1;
51             case "c":
52                 return 0.01;
53             case "m":
54                 return 0.001;
55             case "ยต":
56                 return 0.000001;
57             case "n":
58                 return 0.000000001;
59         }
60         return 1;
61     }
62 }