Example usage for java.lang Float intValue

List of usage examples for java.lang Float intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Float as an int after a narrowing primitive conversion.

Usage

From source file:Main.java

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

    int i = floatObject.intValue();
    System.out.println("int:" + i);
}

From source file:Main.java

public static void main(String[] args) {

    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);//from ww  w  .j  a  v a 2 s  .  c o  m

    short s = fObj.shortValue();
    System.out.println(s);

    int i = fObj.intValue();
    System.out.println(i);

    float f = fObj.floatValue();
    System.out.println(f);

    double d = fObj.doubleValue();
    System.out.println(d);
}

From source file:Main.java

/**
 * @param context//from w w w . ja  v a  2  s. c o  m
 * @param px
 * @return
 */
public static float px2sp(Context context, Float px) {
    if (context == null) {
        return px.intValue();
    }
    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
    return px / scaledDensity;
}

From source file:Main.java

public static String distToString(Float dist) {
    if (dist == null) {
        return "";
    }/*www.  j  a va 2s. c  o m*/
    if (dist > 999) {
        return String.format("%.2fkm", dist / 1000);
    } else {
        return String.format("%dm", dist.intValue());
    }
}

From source file:es.emergya.cliente.constants.LogicConstantsUI.java

public static Font deriveBoldFont(Float f) {
    Integer i = f.intValue();
    Font font = fonts_bold.get(i);
    if (font == null) {
        font = LogicConstantsUI.boldFont.deriveFont(f);
        fonts_bold.put(i, font);/* w  w  w.ja  v  a 2 s.c  o m*/
    }
    return font;
}

From source file:es.emergya.cliente.constants.LogicConstantsUI.java

public static Font deriveLightFont(Float f) {
    Integer i = f.intValue();
    Font font = fonts_light.get(i);
    if (font == null) {
        font = LogicConstantsUI.lightFont.deriveFont(f);
        fonts_light.put(i, font);/*from   w  w  w.j  ava2 s.  c om*/
    }
    return font;
}

From source file:es.emergya.cliente.constants.LogicConstants.java

public static Font deriveBoldFont(Float f) {
    Integer i = f.intValue();
    Font font = fonts_bold.get(i);
    if (font == null) {
        font = LogicConstants.boldFont.deriveFont(f);
        fonts_bold.put(i, font);//from   w  w  w .  java2 s.c o m
    }
    return font;
}

From source file:es.emergya.cliente.constants.LogicConstants.java

public static Font deriveLightFont(Float f) {
    Integer i = f.intValue();
    Font font = fonts_light.get(i);
    if (font == null) {
        font = LogicConstants.lightFont.deriveFont(f);
        fonts_light.put(i, font);/*  www  .j a  va 2 s . com*/
    }
    return font;
}

From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java

/**
 * ?/*  w  w w  .  j a v a 2  s  .  c om*/
 * 
 * @param str
 * @return
 */
public static Integer strToInt(String str) {
    try {
        Float num = Float.parseFloat(str);
        return num.intValue();
    } catch (Exception e) {
        return null;
    }
}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Safely converts a number to an integer. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    number to parse/*from   w  ww.  j  a  v a 2s  .com*/
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static int toInteger(Object obj) {

    /* Switch on class and convert to an int */

    String type = obj.getClass().getSimpleName();
    int parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = by.intValue();
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = sh.intValue();
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = in.intValue();
        break;

    case "Long":
        Long lo = (Long) obj;
        if (!OverFlowUtil.intOverflow(lo)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = lo.intValue();
        break;

    case "Float":
        Float fl = (Float) obj;
        if (!OverFlowUtil.intOverflow(fl)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = fl.intValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) obj;
        if (!OverFlowUtil.intOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = bi.intValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) obj;
        if (!OverFlowUtil.intOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = bd.intValue();
        break;

    case "Double":
        Double db = (Double) obj;
        if (!OverFlowUtil.intOverflow(db)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = db.intValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}