Convert it into a string. (Possibly using the NumberFormat class) Then use
the indexOf (".") to get the decimal place and then convert the parts back
to integers. For example,
float num = 3.4;
String str = ""+num;
int wholeNumber = 0, decimalNumber = 0;
if (str.indexOf (".") > 0) // It should never be zero
{
String beforeDecimal, afterDecimal;
afterDecimal = str.substring (str.indexOf (".") + 1);
beforeDecimal = str.substring (0, str.indexOf ("."));
try
{
wholeNumber = Integer.valueOf (beforeDecimal).intValue ();
decimalNumber = Integer.valueOf (afterDecimal).intValue ();
}
catch (Throwable t)
{
}
}
else
{
try
{
wholeNumber = Integer.valueOf (str).intValue ();
}
catch (Throwable t)
{
}
}
Paul Franz
----- Original Message -----
From: "Jeff Fisher" <[EMAIL PROTECTED]>
To: "JDJList" <[EMAIL PROTECTED]>
Sent: Wednesday, September 04, 2002 8:01 AM
Subject: [jdjlist] modf in in java
> Does java have anything like the modf c function? I checked the math
class,
> but there is just ciel and floor. I can get the first part of the double
> value by casting as to an int, but the fractional part is not so easy. I
> can get it as a double, but I'd like it as an integer.
>
> So what I'm trying to do here is split the number 123.45 into 123 and 45.
>
> Any thoughts?
>
> Thanks
>
> Jeff
>
> To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
>
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm