Here you can find the source of castDoubleToFloat(final double v)
Parameter | Description |
---|---|
v | the double |
Parameter | Description |
---|---|
ArithmeticException | if the <code> v </code> is out of range. |
v
public static float castDoubleToFloat(final double v) throws ArithmeticException
//package com.java2s; //License from project: Open Source License public class Main { /**/*w ww.java2 s.co m*/ * Safely cast a double to a float. * * @param v the double * @return the casted float of <code>v</code> * @throws ArithmeticException if the <code> v </code> is out of range. */ public static float castDoubleToFloat(final double v) throws ArithmeticException { if (Math.abs(v) > Float.MAX_VALUE) { throw new ArithmeticException("casted value is out of the range of float"); } return (float) v; } }