Home arrow static arrow Java Programming [Archive] - easy question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - easy question
This topic has 4 replies on 1 page.

Posts:25
Registered: 7/30/03
easy question  
Aug 9, 2004 2:40 AM



 
getting a double number like 12.66, how to get 12 and 66 seperatly.

thanks for help
 

Posts:18
Registered: 3/4/03
Re: easy question  
Aug 9, 2004 2:46 AM (reply 1 of 4)



 
double d = 12.66;
int i = (int) d;
double x = d-i; // would work with modulo as well i think
 

Posts:2,909
Registered: 13.8.2003
Re: easy question  
Aug 9, 2004 2:47 AM (reply 2 of 4)



 
If you want them as Strings, the easiest way would be:
String s[] = Double.toString(myDouble).split(".");
 

Posts:11,186
Registered: 06.04.04
Re: easy question  
Aug 9, 2004 2:50 AM (reply 3 of 4)



 
getting a double number like 12.66, how to get 12 and 66 seperatly.

How 'bout this --
public static double intPart(double d) { return (d < 0)?Math.ceil(d):Math.floor(d); }public static double frcPart(double d) { return d-intPart(d); } 

kind regards,

Jos
 

Posts:29
Registered: 10/10/01
Re: easy question  
Aug 9, 2004 10:27 AM (reply 4 of 4)



 
getting a double number like 12.66, how to get 12 and
66 seperatly.

thanks for help

double yourNumber = 12.66;
int beforeDecimal = (int)yourNumber); // this will truncate and only return 12
int afterDecimal = yourNumber % 1; // this will use modulus and return 66
 
This topic has 4 replies on 1 page.