By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,198 Members | 1,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,198 IT Pros & Developers. It's quick & easy.

How do I remove the DECIMAL part of a number

P: 4
Hi ppl...

Hope ur havin a good day... here''s my doubt...

I need to remove the decimal part of a number declared as DOUBLE. I can NOT change the type. I need to remove jus the decimal part... any easy solutions to this? I have a way by using the looping.. But a short idea is what I am looking for...

Hoep some one can solve this... :)

Thanks,
Bones'n'Muscles...
Dec 26 '07 #1
Share this Question
Share on Google+
3 Replies


dmjpro
100+
P: 2,476
Hi ppl...

Hope ur havin a good day... here''s my doubt...

I need to remove the decimal part of a number declared as DOUBLE. I can NOT change the type. I need to remove jus the decimal part... any easy solutions to this? I have a way by using the looping.. But a short idea is what I am looking for...

Hoep some one can solve this... :)

Thanks,
Bones'n'Muscles...
You can do this.

Expand|Select|Wrap|Line Numbers
  1. double d = 12345.6789;
  2. d = (double)((int)d);
  3.  
Have a try with this.
I think it may work.

Debasis Jana
Dec 26 '07 #2

Expert 10K+
P: 11,448
You can do this.

Expand|Select|Wrap|Line Numbers
  1. double d = 12345.6789;
  2. d = (double)((int)d);
  3.  
Have a try with this.
I think it may work.

Debasis Jana
That doesn't work; try d=1e42, it's a mathematical integer but it won't fit in an int.
Use Math.rint() instead.

kind regards,

Jos
Dec 26 '07 #3

dmjpro
100+
P: 2,476
That doesn't work; try d=1e42, it's a mathematical integer but it won't fit in an int.
Use Math.rint() instead.

kind regards,

Jos

Yeah that's right.
Thanks for your Suggestion

Debasis Jana
Dec 26 '07 #4

Post your reply

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