Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Extracting whole number digits from a float

  1. #1
    Junior Member Johnny Bravo's Avatar
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Extracting whole number digits from a float

    I need to extract the whole number digits from a number that has decimal point. for example I need only the first 3 digits of a number like 143.454369 which will be 143. I can get it by dividing it with its place value but the problem is that the number will be supplied by the user in my program.

    so I don't know how long the number will be and how to divide it by place value.

    please help.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Extracting whole number digits from a float

    Have you tried casting the number to an int?

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Johnny Bravo (August 12th, 2012)

  4. #3
    Junior Member Johnny Bravo's Avatar
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Extracting whole number digits from a float

    Quote Originally Posted by helloworld922 View Post
    Have you tried casting the number to an int?
    Nope, forgot it but after you've reminded me of casting integer, I did it and the code worked. Thank you so much.

Similar Threads

  1. All Digits only
    By kram in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 28th, 2011, 04:16 PM
  2. Replies: 3
    Last Post: October 19th, 2011, 03:17 PM
  3. Separating Digits in a String
    By Staticity in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 3rd, 2011, 07:39 AM
  4. Remove last digits of an IP address.
    By Jonathan_C in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 15th, 2010, 12:55 PM
  5. Replies: 2
    Last Post: February 4th, 2009, 12:24 PM