Java Number Power powerConverter(String _varSymbol)

Here you can find the source of powerConverter(String _varSymbol)

Description

Converts a unit prefix to power of base 10.

License

Open Source License

Parameter

Parameter Description
_varSymbol Name of the unit represented as String.

Return

Power of the prefix as int.

Declaration

public static int powerConverter(String _varSymbol) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  ww.j a v a 2s  .  c om
     * Converts a unit prefix to power of base 10. This method is probably obsolete since the introduction of the
     * new unit handling in the frontend.
     * TODO: Caution, this method is rather bad and relies on a pretty obsolete representation.
     *
     * @param _varSymbol Name of the unit represented as String.
     * @return Power of the prefix as int.
     */
    public static int powerConverter(String _varSymbol) {
        if (_varSymbol == null || _varSymbol.length() < 2) {
            return 0;
        }
        if (_varSymbol.startsWith("d")) {
            return -1;
        } else if (_varSymbol.startsWith("c")) {
            return -2;
        } else if (_varSymbol.startsWith("m") && _varSymbol.length() > 1) {// in order to avoid confusion between meter and mili
            return -3;
        } else if (_varSymbol.startsWith("mu")) {
            return -6;
        } else if (_varSymbol.startsWith("n")) {
            return -9;
        } else if (_varSymbol.startsWith("p")) {
            return -12;
        } else if (_varSymbol.startsWith("f")) {
            return -15;
        } else if (_varSymbol.startsWith("a")) {
            return -18;
        }
        //positive powers
        else if (_varSymbol.startsWith("da")) {
            return 1;
        } else if (_varSymbol.startsWith("h")) {
            return 2;
        } else if (_varSymbol.startsWith("k")) {
            return 3;
        } else if (_varSymbol.startsWith("M")) {
            return 6;
        } else if (_varSymbol.startsWith("G")) {
            return 9;
        } else if (_varSymbol.startsWith("T")) {
            return 12;
        } else if (_varSymbol.startsWith("P")) {
            return 15;
        } else if (_varSymbol.startsWith("E")) {
            return 18;
        }
        System.err.println(_varSymbol + " prefix not supported!");
        return 1;
    }
}

Related

  1. power(int i)
  2. power(int val, int numOfPower)
  3. power(int x, int n)
  4. power(long x, long y)
  5. power2(int power)
  6. powerLevelToDb(double value)
  7. powerLevelToDb0(double value)
  8. powerMean(final double p, final double[] x)
  9. powerMod(long base, long exp, long mod)