Example of digital formatting usage for Android implementation _android

Source: Internet
Author: User

The examples in this article describe the digital formatting usage that Android implements. Share to everyone for your reference, specific as follows:

Package formatnumber;
Import Java.text.DecimalFormat;  public class FormatNumber {public static void main (string[] args) {DecimalFormat df = new DecimalFormat (); Double data =
1234.56789;
System.out.println ("Pre-formatted number:" + data);  String style = "0.0";//defines the format of the number to display Df.applypattern (style);//applies formatting to the formatter System.out.println (after formatting with style: + style +): "
+ df.format (data));
style = "00000.000 kg";//Add characters such as units Df.applypattern (style) after formatting;
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data));
The "#" in the pattern indicates that if the bit exists, the character is displayed and is not displayed if it does not exist.
style = "# #000 kg";
Df.applypattern (style);
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data));
The "-" in the pattern indicates that the output is negative and should be placed at the front style = "-000.000";
Df.applypattern (style);
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data));
In the pattern, "," adds a comma to the number to facilitate reading the number style = " -0,000.0#";
Df.applypattern (style);
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data)); "E" in the pattern indicates that the output is exponential, the string before "E" is the base format,///"E" after the string is the exponential latticeStyle style = "0.00E000";
Df.applypattern (style);
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data));
The "%" in the pattern is multiplied by 100 and displayed as a percentage, to be placed at the end.
style = "0%";
Df.applypattern (style);
SYSTEM.OUT.PRINTLN ("Use style:" + style + "after formatting:" + df.format (data)); The "\u2030" in the pattern is multiplied by 1000 and displayed as a thousand score, to be placed at the end.
style = "0.00\u2030"; Set the number format in the constructor DecimalFormat df1 = new DecimalFormat (style);
Df.applypattern (style);

 SYSTEM.OUT.PRINTLN ("Use style: + Style +" after formatting: "+ df1.format (data));}

The result of the program running is:

Number before formatting: 1234.56789
after style:0.0 format: 1234.6
with style:00000.000 kg format: 01234.568 kg
uses style: # #000 000 After kg format: 1234.568 kg is formatted
with style:-000.000: -1234.568
adopts style: -0,000.0# after formatting: -1,234.57
adopts style: 0.00E000 after the format: 1.23E003 after the
adoption of style:0.00% format: 123456.79%
adopted style:0.00‰ format: 1,234,567,.89

For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android debugging techniques and common problems solution summary", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary

I hope this article will help you with the Android program.

Related Article

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.