Example usage for java.lang Float compareTo

List of usage examples for java.lang Float compareTo

Introduction

In this page you can find the example usage for java.lang Float compareTo.

Prototype

public int compareTo(Float anotherFloat) 

Source Link

Document

Compares two Float objects numerically.

Usage

From source file:Main.java

public static void main(String[] args) {
    float f1 = 5.5f;
    float f2 = 5.4f;
    int i1 = Float.compare(f1, f2);
    if (i1 > 0) {
        System.out.println(">");
    } else if (i1 < 0) {
        System.out.println("<");
    } else {/*from  w w  w.jav a 2s .c om*/
        System.out.println("=");
    }

    Float fObj1 = new Float("5.5");
    Float fObj2 = new Float("5.4");
    int i2 = fObj1.compareTo(fObj2);
    if (i2 > 0) {
        System.out.println(">");
    } else if (i2 < 0) {
        System.out.println("<");
    } else {
        System.out.println("=");
    }
}

From source file:Main.java

public static void main(String[] args) {
    Float floatObject1 = new Float("10.0001");

    Float floatObject2 = Float.valueOf((float) 0.0 / (float) (0.0));
    System.out.println(floatObject2);

    System.out.println(floatObject1.compareTo(floatObject2));

}

From source file:NumberDemo.java

public static void main(String args[]) {
    Float one = new Float(14.78f - 13.78f);
    Float oneAgain = Float.valueOf("1.0");
    Double doubleOne = new Double(1.0);

    int difference = one.compareTo(oneAgain);

    if (difference == 0) {
        System.out.println("one is equal to oneAgain.");
    } else if (difference < 0) {
        System.out.println("one is less than oneAgain.");
    } else if (difference > 0) {
        System.out.println("one is greater than oneAgain.");
    }/* ww  w. j  a  v a  2  s. c  o m*/

    System.out.println("one is " + ((one.equals(doubleOne)) ? "equal" : "not equal") + " to doubleOne.");

}

From source file:com.highcharts.export.controller.ExportController.java

private static Float scaleToFloat(String scale) {
    scale = sanitize(scale);/*from   w w  w.  j a v a 2s . c  o m*/
    if (scale != null) {
        Float parsedScale = Float.valueOf(scale);
        if (parsedScale.compareTo(MAX_SCALE) > 0) {
            return MAX_SCALE;
        } else if (parsedScale.compareTo(0.0F) > 0) {
            return parsedScale;
        }
    }
    return null;
}

From source file:com.highcharts.export.controller.ExportController.java

private static Float widthToFloat(String width) {
    width = sanitize(width);/*w w w  .  ja v  a  2 s .c  o  m*/
    if (width != null) {
        Float parsedWidth = Float.valueOf(width);
        if (parsedWidth.compareTo(MAX_WIDTH) > 0) {
            return MAX_WIDTH;
        }
        if (parsedWidth.compareTo(0.0F) > 0) {
            return parsedWidth;
        }
    }
    return null;
}

From source file:Highcharts.ExportController.java

private static Float scaleToFloat(String scale) {
        scale = sanitize(scale);//w w w  .ja v a  2 s  .  com
        if (scale != null) {
            Float parsedScale = Float.valueOf(scale);
            if (parsedScale.compareTo(MAX_SCALE) > 0) {
                return MAX_SCALE;
            } else if (parsedScale.compareTo(0.0F) > 0) {
                return parsedScale;
            }
        }
        return null;
    }

From source file:Highcharts.ExportController.java

private static Float widthToFloat(String width) {
        width = sanitize(width);//  w ww .j  a v  a  2 s.c  om
        if (width != null) {
            Float parsedWidth = Float.valueOf(width);
            if (parsedWidth.compareTo(MAX_WIDTH) > 0) {
                return MAX_WIDTH;
            }
            if (parsedWidth.compareTo(0.0F) > 0) {
                return parsedWidth;
            }
        }
        return null;
    }

From source file:com.highcharts.export.controller.ExportController.java

private static Float scaleToFloat(String scale) throws SVGConverterException {
    scale = sanitize(scale);// w ww .  j a va  2s.c  om
    if (scale != null) {
        try {
            Float parsedScale = Float.valueOf(scale);
            if (parsedScale.compareTo(MAX_SCALE) > 0) {
                return MAX_SCALE;
            } else if (parsedScale.compareTo(0.0F) > 0) {
                return parsedScale;
            }
        } catch (NumberFormatException nfe) {
            logger.error("Parameter scale is wrong for value: " + scale, nfe.fillInStackTrace());
            throw new SVGConverterException("Parameter scale is wrong for value: " + scale);
        }
    }
    return null;
}

From source file:com.highcharts.export.controller.ExportController.java

private static Float widthToFloat(String width) throws SVGConverterException {
    width = sanitize(width);//from w  w  w .j a  v a  2s .c  o m
    if (width != null) {
        width = width.replace("px", "");
        try {
            Float parsedWidth = Float.valueOf(width);
            if (parsedWidth.compareTo(MAX_WIDTH) > 0) {
                return MAX_WIDTH;
            }
            if (parsedWidth.compareTo(0.0F) > 0) {
                return parsedWidth;
            }
        } catch (NumberFormatException nfe) {
            logger.error("Parameter width is wrong for value: " + width, nfe.fillInStackTrace());
            throw new SVGConverterException("Parameter width is wrong for value: " + width);
        }

    }
    return null;
}

From source file:org.knowrob.vis.model.util.algorithm.ACCUM.java

/**
 * Sorts ascendingly & in-line a data list of floating point numbers.
 * @param curvData/*from   ww  w  .j a va  2 s  .co m*/
 *          data list to be sorted
 */
private static void sortCurv(final List<Float> curvData) {
    if (curvData != null) {
        Collections.sort(curvData, new Comparator<Float>() {
            @Override
            public int compare(Float c1, Float c2) {
                return c1.compareTo(c2);
            }
        });
    }
}