Java Float to Short floatToShort(float f)

Here you can find the source of floatToShort(float f)

Description

float To Short

License

LGPL

Declaration

public static Short floatToShort(float f) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static Short floatToShort(float f) {
        if (f >= Short.MIN_VALUE && f <= Short.MAX_VALUE) {
            return (short) f;
        }//  w  w  w.  j av  a2s  .  c o  m
        return null;
    }

    public static short floatToShort(float f, short defaultValue) {
        if (f >= Short.MIN_VALUE && f <= Short.MAX_VALUE) {
            return (short) f;
        }
        return defaultValue;
    }
}

Related

  1. floatToShort(final float value)
  2. floatToShort(float[] values)