Results 1 to 4 of 4
  1. #1
    Billaguana is offline Member
    Join Date
    Jan 2011
    Posts
    21
    Rep Power
    0

    Default how to stop decimal in a double array

    I am returning a double array and it sometime contains endless decimals but i would like to end it after three decimal spaces. I have tried using DecimalFormat but will not work on array.

    Any help appreciated

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You need to apply the decimal format to each of the decimals that you intend representing with String instances.

  3. #3
    Billaguana is offline Member
    Join Date
    Jan 2011
    Posts
    21
    Rep Power
    0

    Default

    o, hmm. I was trying to avoid that but if that is it then thanks.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You're welcome.

    Doubles are doubles and Strings are Strings; and it's only the latter which have a base and therefore decimal places etc. Some langauges are quite casual about interchanging these types but Java isn't.

    Also some languages provide a syntax for applying an operation to each of the elements of a collection like an array. But with Java you use a for loop for that.

Similar Threads

  1. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 01:50 PM
  2. Limiting decimal places in a double
    By darek9576 in forum New To Java
    Replies: 5
    Last Post: 03-14-2010, 02:13 AM
  3. rounding double to two decimal places
    By javaMike in forum Advanced Java
    Replies: 15
    Last Post: 03-10-2010, 01:04 AM
  4. Replies: 4
    Last Post: 03-03-2009, 01:43 PM
  5. Replies: 7
    Last Post: 01-12-2008, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •