469,323 Members | 1,567 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Removing decimal points

40
I'm wondering which data type will only give me the whole number and drop off the rest of the fraction?

For example if I have 3.14, but I just want 3, how can i get this done?
Sep 10 '08 #1

✓ answered by chaarmann

Convert the floating point number to an int.
int result = (int) 3.14;

You could also do it with Math.floor() or Math.ceil() or Math.round() or especially Math.rint(), depending in which way you want to cut off.

3 13519
pronerd
392 Expert 256MB
There are a number of API options for controlling output formatting. This will show you what you want.

http://java.sun.com/docs/books/tutor...malFormat.html
Sep 10 '08 #2
chaarmann
785 Expert 512MB
Convert the floating point number to an int.
int result = (int) 3.14;

You could also do it with Math.floor() or Math.ceil() or Math.round() or especially Math.rint(), depending in which way you want to cut off.
Sep 11 '08 #3
samido
52
some titorials:

{
double d = 3.43;
int x ;
double s;
s = x; // right
x = s; // wrong
x = (int)d; //write
x = d; // wrong
. // ???
. // ???
. // ???

}

Sam Rabophala
Sep 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Enno Middelberg | last post: by
7 posts views Thread by hana1 | last post: by
15 posts views Thread by Kay Schluehr | last post: by
13 posts views Thread by Mumia W. | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.