Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Formatting Java floating-point types     - Linux Firewall Basics (Linux)

- Zabbix using Omsa monitor hardware information of Dell server (Server)

- How to write a new Git protocol (Linux)

- SVN common commands (Linux)

- VMware virtual machine to install CentOS 6.2 (Linux)

- How to Install Node.js in CentOS 7 (Linux)

- Using packet capture libpcap be reconciliation package in Ubuntu 14.04 64 bits (Linux)

- How to Install 3.16.7 CKT2 kernel in Ubuntu 14.10, Ubuntu 14.04 and its derivative versions (Linux)

- Use OpenWrt build WDS wireless network extension on V2 WHR-G300N (Linux)

- See how --nand flash timing diagram of a read operation Comments (Programming)

- Using Libreoffice under ubuntu (Linux)

- Oracle PL / SQL based cursor (Database)

- Customize the 404 error page Nginx (Server)

- Sublime Text 3 using summary (Linux)

- OpenResty load balancing MySQL (Database)

- MySQL 5.6 use GTIDs build the master database (Database)

- How to find out a Unix system library files are 32-bit or 64-bit (Linux)

- Ubuntu Locale configuration problem solving Can not set LC_CTYPE (Linux)

- Linux installed Cisco Packet Tracer (Linux)

- Notebook computer forget password solution (Linux)

 
         
  Formatting Java floating-point types
     
  Add Date : 2018-11-21      
         
         
         
  Outline

Based on Java, describes the type of decimal floating point format of the program.

text

In Java, a class is used to format decimal java.text.DecimalFormat, for example, you can use:

double data = 3334590479.22d;
System.out.println (data); // 3.33459047922E9

java.text.DecimalFormat df = new java.text.DecimalFormat ( "$ #, ### ##.");
String result = df.format (data);
System.out.println (result); // $ 3,334,590,479.22

For larger values, mode uses scientific notation (scientific notation); use java.text.DecimalFormat specified format, with the specified format.

Format. "$ #, ### ##" Contains the following semantics:

1. $ prefix
2. Every 3-digit integer part of a group
3. Up to 2 decimal places

About format

A general structure of the format is: Prefixopt Number Suffixopt, namely the prefix + number + suffix; wherein the prefix and suffix are optional.

About Group

Group delimiter, and only the integer part; no matter how many there are delimiters mode, the rightmost that a valid; the number of each group is the rightmost delimiter right hand of integer digits.

Therefore, the "#, ##, ###, ####" == "###### ####" == "##, ####, ####."

About decimals

Decimal separator., Used to separate the integer and fractional parts.

About digital special characters

1. #
# Is a special character for the digital section; it represents a digital display, but the foremost and rearmost 0 not displayed.

data: 02222.20
pattern: "., ### ##"
result: 2,222.2

# There is no limit for the number of bits in the integer part, but for the fractional part, there are "many decimal places can only have the meaning of" excess rounding. such as:

data: 2222.222
pattern: "., ### ##"
result: 2,222.22

2.0
# 0 and usage is similar, but slightly different; except that:
A 0-digit integer part of the least restrictions arise;. Less than the median, preceded by 0

data: 22.26
pattern: "0,000.00"
result: 0,022.26

. B 0 limit number of fractional digits appear; if less than 0, more rounded

data: 22.26
-----------------
pattern: "00.000"
result: 22.260
-----------------
pattern: "00.0"
result: 22.3

3. E
Scientific notation, mantissa and exponent separator.
Details, see below.

About prefixes, suffixes

In addition to \ uFFFE, \ uFFFF special characters and any Unicode character can be used as a prefix, suffix; there are four special characters:

1. %
The number is multiplied by 100

data: 1234.567
pattern: "., ### ##%"
result: 123,456.7%

2. \ u2030
The number by 1000

data: 1234.567
pattern: "., ### ## \ u2030"
result: 1,234,567

3. (\ u00A4)
Localized currency symbol, if two consecutive, on behalf of the international currency symbol codes.

data: 1234.567
---------------------
pattern: "., ### ## "
result: 1,234.57
---------------------
pattern: "., ### ## "
result: 1,234.57

4. '
Used to refer to special characters, as a prefix or suffix.

data: 1234.567
pattern: ". '#', ### ##"
result: # 1,234.57

If you want to use the 'itself as a prefix or suffix, input twice in succession:

data: 1234.567
pattern: ". '', ### ##"
result: '1,234.57

Scientific notation

Scientific notation is added as E0 digital content in the tail section, where E is the mantissa and exponent separator, the number behind the E 0 represents the minimum number of indices (less than 0 up front).

data: 1E5
pattern: 0. # E00
result: 1E05 // Note that there are two indices

E content must be in front of, or at least a # 0, otherwise it is treated as a prefix E handled:

data: 1E5
---------------
pattern: "E0"
result: E100000
---------------
pattern: "0E0"
result: 1E5
---------------
pattern: "# E0"
result: .1E6

Exponent part is not much content, discussed below mantissa part.

Mantissa generally includes integers and fractions, if the integer part no content (no content front.), Valid on all the decimal numbers:

data: 12345E5
pattern: ". ### E0"
result: .123E10

If the integer part of the need to retain few, on the use of several 0 (# use the results of a little bizarre, all of you to try):

data: 12345E5
----------------------
pattern: ". 0 ### E0"
result: 1.234E9
----------------------
pattern: ". 00 ### E0"
result: 12.345E8
---------------------
pattern: ". 000 ### E0"
result: 123.45E7

Fractional part, if you want to achieve "up to several decimal places reserved" effect, in the pattern. After adding a # corresponding. This excess will be rounded up; if you want to achieve "just a few decimal reserved" effect, after the addition of the pattern of the corresponding zeros. Thus, the lack of will in the back fill 0, the excess will be rounded.

data: 123E5
------------------
pattern: "0. # E0"
result: 1.2E7
------------------
pattern: ". 0 ## E0"
result: 1.23E7
------------------
pattern: ". 0 ### E0"
result: 1.23E7
==================
pattern: "0.0E0"
result: 1.2E7
------------------
pattern: "0.00E0"
result: 1.23E7
------------------
pattern: "0.000E0"
result: 1.230E7
     
         
         
         
  More:      
 
- Ubuntu ADSL dial-up Internet access (Linux)
- CentOS modify yum update source (Linux)
- How to back up Debian system backupninja (Linux)
- Linux netstat command to get started (Linux)
- High-performance JavaScript reflows and repaints (Programming)
- Linux unpack the tar file to a different directory (Linux)
- Source encountered problems and solutions when installing SaltStack (Server)
- Let Linux boot methods to enter characters interface and set FrameBuffer resolution methods (Linux)
- Node.js simple interface server (Server)
- Linux tool curl and wget advanced use (Linux)
- Puppet 3.x installed on Debian 7 (Server)
- Under CentOS yum install Nginx smooth switch mounted to Tengine (Server)
- PL / SQL -> UTL_FILE use presentation package (Database)
- Linux Network Programming - libnet Guide (Programming)
- To install the Git and Github under Ubuntu (Linux)
- Compiling source code Nginx module installation subs_filter (Server)
- Simple to use Linux GPG (Linux)
- cat command uses the Linux redirection merge files (Linux)
- PSUADE installation under Linux (Linux)
- Safety testing Unix and Linux server entry succinctly (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.