Java Bit Shift shiftDouble(Object o, double shift, String suffix)

Here you can find the source of shiftDouble(Object o, double shift, String suffix)

Description

shift Double

License

Open Source License

Parameter

Parameter Description
o A string representation of a double value.
shift Increments or decrements the parsed value.
suffix A string appended to the result.

Declaration

public static String shiftDouble(Object o, double shift, String suffix) 

Method Source Code

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

public class Main {
    /**//from ww  w. j  a v a  2  s  . co m
     * @param o A string representation of a double value.
     * @param shift Increments or decrements the parsed value.
     * @param suffix A string appended to the result.
     */
    public static String shiftDouble(Object o, double shift, String suffix) {
        Double d = parseDouble(o);
        d = d + shift;
        return (String.format("%.1f", d) + suffix);
    }

    /**
     * @param o A string representation of a double value.
     * @return The parsed value or 0.0 if the string couldn't be parsed.
     */
    public static Double parseDouble(Object o) {
        String s = o.toString();
        try {
            if (s.length() >= 1) {
                return (Double.parseDouble(s.substring(0, s.length() - 1)));
            } else {
                return (0.0);
            }
        } catch (NumberFormatException e) {
            return (0.0);
        }
    }
}

Related

  1. shift(int length)
  2. shift(String string)
  3. shiftBits(byte b)
  4. shiftByte(byte n, short shift)
  5. shiftCharacter(char c, int offset)
  6. shiftHorizontally(int inkX, int inkXWidth, int textWidth)
  7. shiftIdentifier(StringBuffer buffer, int posBegin, int posEnd)
  8. shiftKeyword(StringBuffer buffer, int posBegin, int posEnd, String keyword, boolean ignoreCase, boolean wholeWord)
  9. shiftLastAlphabets(String id)