Double into Float

Hey all,

Ive got a Double and I want to convert it to a Float and I want to check its within the IEEE 754 standards of the highest value you can have and lowest...

But I can't parse it, as Ive found out and .floatValue() doesn't throw an error as im aware, So I was wondering if you had any ideas

Double tmpDouble;

tmpDouble =new Double(anaObj.getValue());

float tmpFloat = 0f;

try

{

tmpFloat = tmpDouble.floatValue();

}

catch (NumberFormatException nfe)

{

Logger.writeLogMessage(Logger.WARNING, nfe.getMessage());

}

[843 byte] By [Karen_a] at [2007-11-27 8:40:01]
# 1
what about?if (tmpDouble < Float.MAX_VALUE && tmpDouble > Float.MIN_VALUE){tmpFloat = tmpDouble.floatValue();}Message was edited by: petes1234
petes1234a at 2007-7-12 20:38:16 > top of Java-index,Java Essentials,New To Java...
# 2

or may need something like this, I'm not sure:

if (tmpDouble < Float.MAX_VALUE &&

tmpDouble > Float.MIN_VALUE &&

Math.getExponent(tmpDouble) > Float.MIN_EXPONENT &&

Math.getExponent(tmpDouble) < Float.MAX_EXPONENT)

{

tmpFloat = tmpDouble.floatValue();

}

petes1234a at 2007-7-12 20:38:17 > top of Java-index,Java Essentials,New To Java...
# 3
ahh yeah!Ill work with it a while and get back to youThanks petes1234!
Karen_a at 2007-7-12 20:38:17 > top of Java-index,Java Essentials,New To Java...