Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java numner formatting

Options
  • 14-04-2005 11:38am
    #1
    Registered Users Posts: 4,222 ✭✭✭


    How can you format a number in java (say integer value 8) so that it is in the following format:

    0000000008

    cheers!



Comments

  • Registered Users Posts: 1,272 ✭✭✭i_am_dogboy


    You need to import java.text.NumberFormat

    then something like

    NumberFormat nf = NumberFormat.getInstance() ;
    nf.setMinimumIntegerDigits(10) ;
    nf.format(var) ;

    btw nf.format returns a string


  • Registered Users Posts: 4,222 ✭✭✭Scruff


    cheers.

    that however outputs the string in the following format "0,000,000,008".
    I need it without the "," seperators

    /edit
    ye put me on the right though.
    The solution is:

    NumberFormat nf= new DecimalFormat("00000000");
    String s = nf.format(8);

    which gives "0000008"

    Thanks for the help!


Advertisement