1 package org.wcb.e6b;
2
3 import java.text.DecimalFormat;
4
5 /**
6 * <small>
7 * <p/>
8 * Copyright (C) 2006 wbogaardt.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 * <p/>
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 * <p/>
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * <p/>
23 * $File: $ <br>
24 * $Change: $ submitted by $Author: wbogaardt $ at $DateTime: Nov 14, 2006 1:58:30 PM $ <br>
25 * </small>
26 *
27 * @author wbogaardt
28 * Utility to do some standard conversions.
29 */
30
31 public class E6bConverter {
32
33 private static final DecimalFormat DEC_FORMATER = new DecimalFormat("###,###.##");
34
35 public static String format(double val) {
36 return DEC_FORMATER.format(val);
37 }
38
39 public static double celsiusToFahrenheit(double celsius) {
40 return ((9.0 / 5.0) * celsius) + 32;
41 }
42
43 public static double fahrenheitToCelsius(int fahrenheit) {
44 return (fahrenheit - 32) * (5.0 / 9.0);
45 }
46
47 public static double knotsToMiles(int knots) {
48 return knots * 1.15077945;
49 }
50
51 public static double milesToKnots(int miles) {
52 return miles * 0.86897624;
53 }
54
55 public static double litersToGallons(int gallons) {
56 return gallons * 0.264172051;
57 }
58
59 public static double gallonsToLiters(int liters) {
60 return liters * 3.7854118;
61 }
62
63 public static double nauticalToKilometer(int nm) {
64 return nm * 1.852;
65 }
66
67 public static double kilometerToNautical(int km) {
68 return km / 1.852;
69 }
70
71 /**
72 * Convert Millibars to inches mercury Hg.
73 * @param pressure in millibars standard is 1013.2078880000001
74 * @return the HG equilvalent
75 */
76 public static double millibarsToHg(double pressure) {
77 return pressure * .02953;
78 }
79
80 /**
81 * Convert inches Mercury HG to Millibars.
82 * @param pressure inches of mercury standard is 29.92
83 * @return milibar equivalent
84 */
85 public static double hgToMillibars(double pressure) {
86 return pressure * 33.8639;
87 }
88
89 public static double centigradeToKelvin(double centigradeTemp) {
90 return 273.15 + centigradeTemp;
91 }
92
93 }