![]() |
||
![]() |
![]() Alden Hosting provides professional, efficient, and reliable business-class Web hosting services to small- and medium-sized businesses. |
|
|
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER, |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Converter | Flag | Explanation |
|---|---|---|
| d | A decimal integer. | |
| f | A float. | |
| n |
A new line character appropriate
to the platform running the application. You should
always use %n, rather than \n.
|
|
| tB | A date & time conversion—locale-specific full name of month. | |
| td, te | A date & time conversion—2-digit day of month. td has leading zeroes as needed, te does not. | |
| ty, tY | A date & time conversion—ty = 2-digit year, tY = 4-digit year. | |
| tl | A date & time conversion—hour in 12-hour clock. | |
| tM | A date & time conversion—minutes in 2 digits, with leading zeroes as necessary. | |
| tp | A date & time conversion—locale-specific am/pm (lower case). | |
| tm | A date & time conversion—months in 2 digits, with leading zeroes as necessary. | |
| tD | A date & time conversion—date as %tm%td%ty | |
| 08 | Eight characters in width, with leading zeroes as necessary. | |
| + | Includes sign, whether positive or negative. | |
| , | Includes locale-specific grouping characters. | |
| - | Left-justified.. | |
| .3 | Three places after decimal point. | |
| 10.3 | Ten characters in width, right justified, with three places after decimal point. |
The following program shows some of the formatting that you can do
with format(). The
java.util package must be imported as it contains the Locale
and Calendar classes:
import java.util.*;
public class TestFormat {
public static void main(String[] args) {
long n = 461012;
System.out.format("%d%n", n);
System.out.format("%08d%n", n);
System.out.format("%+8d%n", n);
System.out.format("%,8d%n", n);
System.out.format("%+,8d%n%n", n);
double pi = Math.PI;
System.out.format("%f%n", pi);
System.out.format("%.3f%n", pi);
System.out.format("%10.3f%n", pi);
System.out.format("%-10.3f%n", pi);
System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi);
Calendar c = Calendar.getInstance();
System.out.format("%tB %te, %tY%n", c, c, c);
System.out.format("%tl:%tM %tp%n", c, c, c);
System.out.format("%tD%n", c);
}
}
The output is:
461012
00461012
+461012
461,012
+461,012
3.141593
3.142
3.142
3.142
3,1416
May 29, 2006
2:34 am
05/29/06
Note: The discussion in this section covers just the basics of theformat()andprintf()methods. Further detail can be found in theBasic I/Osection titled "Formatting."
java.text.DecimalFormat class to control
the display of leading and trailing zeros, prefixes and suffixes,
grouping (thousands) separators, and the decimal separator. DecimalFormat offers a great deal of
flexibility in the formatting of numbers, but it can make your code more complex.
The example that follows creates a DecimalFormat object, myFormatter,
by passing a pattern string to the DecimalFormat
constructor. The format() method, which DecimalFormat
inherits from NumberFormat, is then invoked by myFormatter—it accepts a double
value as an argument and returns the formatted number in a string:
Here is a sample program that illustrates the use of DecimalFormat:
import java.text.*;
public class DecimalFormatDemo {
static public void customFormat(String pattern, double value ) {
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(value);
System.out.println(value + " " + pattern + " " + output);
}
static public void main(String[] args) {
customFormat("###,###.###", 123456.789);
customFormat("###.##", 123456.789);
customFormat("000000.000", 123.78);
customFormat("$###,###.###", 12345.67);
}
}
The output is:
123456.789 ###,###.### 123,456.789 123456.789 ###.## 123456.79 123.78 000000.000 000123.780 12345.67 $###,###.### $12,345.67
The following table explains each line of output.
| Value | Pattern | Output | Explanation |
|---|---|---|---|
| 123456.789 | ###,###.### | 123,456.789 | The pound sign (#) denotes a digit, the comma is a placeholder for the grouping separator, and the period is a placeholder for the decimal separator. |
| 123456.789 | ###.## | 123456.79 |
The value has three digits to the right of the decimal
point, but the pattern has only two. The
format method handles this by rounding up.
|
| 123.78 | 000000.000 | 000123.780 |
The pattern specifies leading and trailing zeros, because
the 0 character is used instead of the pound sign (#).
|
| 12345.67 | $###,###.### | $12,345.67 |
The first character in the pattern is the dollar sign ($).
Note that it immediately precedes the leftmost digit in the formatted
output.
|
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans WEB 4 PLAN and WEB 5 PLAN , WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing affordable, quality and efficient Java web hosting in the shared hosting marketplace. All our sites run on our Java hosing platform configured for optimum performance using Java 1.6, Tomcat 6, MySQL 5, Apache 2.2 and web application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private Tomcat environment get their very own Tomcat server. You can start and re-start your entire Tomcat server yourself.
![]() |
|
http://alden-servlet-Hosting.com
JSP at alden-servlet-Hosting.com
Servlets at alden-servlet-Hosting.com
Servlet at alden-servlet-Hosting.com
Tomcat at alden-servlet-Hosting.com
MySQL at alden-servlet-Hosting.com
Java at alden-servlet-Hosting.com
sFTP at alden-servlet-Hosting.com
http://alden-tomcat-Hosting.com
JSP at alden-tomcat-Hosting.com
Servlets at alden-tomcat-Hosting.com
Servlet at alden-tomcat-Hosting.com
Tomcat at alden-tomcat-Hosting.com
MySQL at alden-tomcat-Hosting.com
Java at alden-tomcat-Hosting.com
sFTP at alden-tomcat-Hosting.com
http://alden-sftp-Hosting.com
JSP at alden-sftp-Hosting.com
Servlets at alden-sftp-Hosting.com
Servlet at alden-sftp-Hosting.com
Tomcat at alden-sftp-Hosting.com
MySQL at alden-sftp-Hosting.com
Java at alden-sftp-Hosting.com
sFTP at alden-sftp-Hosting.com
http://alden-jsp-Hosting.com
JSP at alden-jsp-Hosting.com
Servlets at alden-jsp-Hosting.com
Servlet at alden-jsp-Hosting.com
Tomcat at alden-jsp-Hosting.com
MySQL at alden-jsp-Hosting.com
Java at alden-jsp-Hosting.com
sFTP at alden-jsp-Hosting.com
http://alden-java-Hosting.com
JSp at alden-java-Hosting.com
Servlets at alden-java-Hosting.com
Servlet at alden-java-Hosting.com
Tomcat at alden-java-Hosting.com
MySQL at alden-java-Hosting.com
Java at alden-java-Hosting.com
sFTP at alden-java-Hosting.com
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP at JSP.aldenWEBhosting.com
Servlets at servlets.aldenWEBhosting.com
Tomcat at Tomcat.aldenWEBhosting.com
mysql at mysql.aldenWEBhosting.com
Java at Java.aldenWEBhosting.com
Web Hosts Portal
Web Links
Web Links
Web Hosting
JSP Solutions Web Links
JSP Solutions Web Hosting
Servlets Solutions Web Links
Servlets Solutions Web Hosting
Web Links
Web Links
.
.
.
.
.
.
.
.
.
.
jsp hosting
servlets hosting
web hosting
web sites designed
cheap web hosting
web site hosting
myspace web hosting