<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eTechTips &#187; formatting</title>
	<atom:link href="http://www.etechtips.com/tag/formatting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etechtips.com</link>
	<description>Your Technical resource</description>
	<lastBuildDate>Thu, 29 Jul 2010 04:01:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java formatting a number with leading zeroes</title>
		<link>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/</link>
		<comments>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 05:10:56 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[formatting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=53</guid>
		<description><![CDATA[Recently, I had a Java project that needed to encode a set of numbers and I needed a fixed number of digits used for each number.  I found the DecimalFormat class a good solution for my needs.
Here is a snippet of code to show a simple way to format a number with a fixed [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I had a Java project that needed to encode a set of numbers and I needed a fixed number of digits used for each number.  I found the DecimalFormat class a good solution for my needs.</p>
<p>Here is a snippet of code to show a simple way to format a number with a fixed number of digits.</p>
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>import java.text.DecimalFormat;

class TestEncoder
{
        public static void main(String[] args)
        {
                // This program expects one integer
                // argument and places it in the num1
                // variable. This program is not very
                // robust as to watch for no arguments
                // or to check if the argument is not
                // an integer.
                String num1 = args[0];
                String output;

                // This creates the Decimal Format instance
                // and assigns the formatting that we want
                // to use, in this case three characters .
                DecimalFormat dfmt =
                             new DecimalFormat(&quot;000&quot;);

                // This does the work of formatting the number
                // passed in on the command line to be at least
                // three digits.
                output = dfmt.format(new Integer(num1));

                // This just displays the results of the
                // dfmt.format(new Integer(num1)) command.
                System.out.println(&quot;Output: &quot; + output);
}
}
</code></pre>
<p>The Decimal format allows for many more formatting options for numbers.</p>
<p>Make sure to look a the API docs for the version of Java that you are using:</p>
<p>http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2009/07/17/java-formatting-a-number-with-leading-zeroes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
