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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

java numner formatting

  • 14-04-2005 10:38am
    #1
    Registered Users, Registered Users 2 Posts: 4,225 ✭✭✭


    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, Registered Users 2 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, Registered Users 2 Posts: 4,225 ✭✭✭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