Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

java numner formatting

  • 14-04-2005 11:38AM
    #1
    Registered Users, Registered Users 2 Posts: 4,228 ✭✭✭


    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,228 ✭✭✭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