Adblock breaks this site

Small question from a newbie

Discussion in 'Programming General' started by Tiemen, Aug 1, 2010.

  1. Tiemen

    Tiemen Grand Master
    Banned

    Joined:
    Mar 21, 2010
    Posts:
    3,913
    Referrals:
    1
    Sythe Gold:
    0
    Small question from a newbie

    I'm currently making a task for university but i cant find this in my sillabus anywhere :O
    How can i round a double to a certain amount of digits?
    I know the things like Math.floor, Math.ceil, Math.rint and Math.round....

    So basically i want

    1.111 instead of 1.1111111111111112
     
  2. blindkilla

    blindkilla Guru
    $25 USD Donor New

    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord
    Small question from a newbie

  3. db0winsanity

    db0winsanity Active Member

    Joined:
    Dec 28, 2008
    Posts:
    109
    Referrals:
    0
    Sythe Gold:
    0
    Small question from a newbie

    Code:
    public class roundToThree {
         public static void main(String[] args){
                 DecimalFormat twoDForm = new DecimalFormat("#.###");
                  System.out.println(twoDForm.format(10.1234));
         }
    }
     
  4. Tiemen

    Tiemen Grand Master
    Banned

    Joined:
    Mar 21, 2010
    Posts:
    3,913
    Referrals:
    1
    Sythe Gold:
    0
    Small question from a newbie

    Thanks for the replies :)
    Anyways, created my own method already to do it (multiply, round, divide), so I only use things I've learnt yet :D
     
  5. db0winsanity

    db0winsanity Active Member

    Joined:
    Dec 28, 2008
    Posts:
    109
    Referrals:
    0
    Sythe Gold:
    0
    Small question from a newbie

    Glad i could help, even if you didnt use it haha
     
< Creating own MMORPG | [GREAT CLIENT] Selling Affliction client [CHEAP] >


 
 
Adblock breaks this site