Keep in mind that "." is not the decimal separator in all countries in the world. For example, "," is the character used in several countries...
> -----Original Message----- > From: Paul Franz [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, September 04, 2002 8:23 AM > To: JDJList > Subject: [jdjlist] Re: modf in in java > > > 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 The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it. To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
