471,887 Members | 1,459 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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 14773
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 YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.