🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8426

Re: * Pad a digit

#8426
From: John McGrath TeamB
Date: Wed, 21 Mar 2001 05:48
25 lines
1466 bytes
On Tue, 20 Mar 2001 11:42:07 -0500, ComputerGuy wrote:

> I want a function to pad a digit with preceding zeroes of a
> predetermined length.  For example, Pad(345,5) will give me
> "00345" and Pad(4,5) will give me "00004".
> 
> Is there a Java function that does this?

It is easy to write using the DecimalFormat class:
 
    public static String pad( int value, int length ) {
        DecimalFormat df = new DecimalFormat();
        df.setMinimumIntegerDigits( length );
        df.setGroupingUsed( false );
        return df.format( value );
    }

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.15220a96714ae96a98a08e@forums.borland.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.visi.com!hermes.visi.com!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!209.92.40.60
References: <3ab78784$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,594a95011dde651b
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-23 03:56:05 PST
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: * Pad a digit
Date: Wed, 21 Mar 2001 00:48:09 -0500
Message-ID: <MPG.15220a96714ae96a98a08e@forums.borland.com>
References: <3ab78784$1_2@dnews>
X-Newsreader: MicroPlanet Gravity v2.30
NNTP-Posting-Host: 209.92.40.60
X-Trace: 20 Mar 2001 21:44:15 -0800, 209.92.40.60
Lines: 25
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.visi.com!hermes.visi.com!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!209.92.40.60