Problems with Java String.Format ()

Source: Internet
Author: User

Code =======================================================
float floattype=1000.00f;
Double doubletyep=11111111111111111.00d;
Date Datetype = new Date ();
String floatstr = String.Format ("%a,%e,%f,%g", Floattype,floattype,floattype,floattype);
String doublestr = String.Format ("%a,%e,%f,%g", Doubletyep,doubletyep,doubletyep,doubletyep);
String datastr = String.Format ("%1$tm-%1$te-%1$ty", Datetype);
System.out.println (FLOATSTR);
System.out.println (DOUBLESTR);
System.out.println (DATASTR);
===============================================================
Output Result:
0X1.F4P9, 1.000000e+03, 1000.000000, 1000.00
0X1.3BCBF936B38E4P53, 1.111111e+16, 11111111111111112.000000, 1.11111e+16
06-15-2009

where float type and double type of data, for the String.Format () method,
are all represented as floating-point numbers,
The format parameters you can use are as follows:
String.Format ("%a,%e,%f,%g", Floattype,floattype,floattype,floattype);
which
%a means hexadecimal representation
%e the expression of scientific notation
%f represents the normal 10 binary
%g represents the size of a value based on the actual type, or in the manner of%e, or by%f

For a date type:
Such as:
String datastr = String.Format ("%1$tm-%1$te-%1$ty", Datetype);
Where 1$ means that if there are more than one datetype in the argument, then which value in Datetype is taken,
T represents a date or time format,
M represents the month, E represents the day, and Y represents the year.

Problems with Java String.Format ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.