Collection
zero Useful+1
zero

Normalized floating point number

A floating point number is converted in the specified format
This entry is missing Overview , add relevant content to make the entry more complete, and it can also be upgraded quickly. Hurry up edit Come on!
Normalized floating point numbers, also known as formatted output, refer to Floating point number Convert in the specified format. Formatting is usually required for report statistics display, data calculation and storage. Common formatting functions are: format , cast, etc.
Chinese name
Normalized floating point number
Also called
Format Output
Definition
It refers to entering a floating point number in the specified format
Formatting Functions
format,cast

Principles of Computer Composition

Announce
edit
If not Floating point number The representation of the same floating point number is not unique. For example, Decimal number It can be expressed as 1.11 × 10 zero ,0.111×10 one ,0.0111×10 two And other forms. To improve the precision of data representation, when Mantissa When the value of is not 0, the most significant bit of the mantissa field should be 1, which is called the Normalization express. Otherwise, modify Order code Move left and right at the same time decimal point Position the method to make it into the form of normalized number.
But in IEEE754 standard The true value of a normalized 32-bit floating point number x is expressed as:
x=(-1) S ×(1.M)×2 (E-127) (e=E-127) where S is the sign bit of floating point number, accounting for 1 bit. M is the mantissa, which is placed in the lower part and occupies 23 digits. The decimal point is placed in the leftmost (highest) mantissa field Significant bit To the right of. E is an order code, occupying 8 bits. Its mantissa field represents 1. M. E is the actual index. Because the leftmost digit (most significant digit) of the mantissa field of a normalized floating point number is always 1, this digit is often not stored, but is thought to be hidden to the left of the decimal point.
64 bit Floating point number The middle sign bit is 1 bit, the order code field is 11 bits, the mantissa field is 52 bits, and the exponential offset value is 1023. Therefore, the true value of the normalized 64 bit floating point number x is
x=(-1) S ×(1.M)×2 (E-1023) (e=E-1023)

Special circumstances

When Order code When E is all 0 and the mantissa is all 0, the true value x represented is zero, and the combined sign bit S is 0 or 1, which can be divided into positive zero and negative zero. When the order code E is all 1 and the mantissa M is all 0, the true value x represented is infinite, and the combined sign bit S is 0 or 1, there are also+∞ and - ∞. This is in 32-bit Floating point number In the representation, to remove the special case that E uses all 0 and all 1 (255 in decimal system) to represent zero and infinity, the offset value of the index is not 128 (10000000), but 127 (01111111). For a normalized floating point number, the range of E becomes 1 to 254, and the real exponential value e is - 126 to+127. Therefore, a 32-bit floating point number represents absolute value The range of is 10 -38 ~10 thirty-eight (Expressed as a power of 10).

Example 1

take Decimal number 11.375 means 754 standard Storage format (It is a kind of normalized floating point number mentioned above international standard
11.375=+1011.011=+(1.011011)×2 three =(-1) S ×(1.M)×2 e
It can be seen that S=0, including the mantissa of hidden bit 1 1. M=1.011011=1.011 0110 0000 0000 0000 0000
e=3
E=e+127=130=011+01111111=10000010
be Binary number Format is
0 1000 0010 0110 1100 0000 0000 0000 0000
- ------------- ---------------------------
↑ ↑ ↑
S Order code (8 bits) mantissa (23 bits)

Example 2

create table Floating point number (floating point number);
Insert into floating point values (1.00);
Insert into floating point values (1.10);
Insert into floating point values (1.021);
Insert into floating point values (1.01);
Insert into floating point values (100.2);
Insert into floating point values (0.586);
Insert into floating point values (299.999);
insert into Floating point number values(53.000);
Insert into floating point values (35003.12);
.mode column
.h on
Select * from floating point number;
Floating point number
----------
one
one point one
three hundred
one point zero two one
one point zero one
one hundred point two
zero point five eight six
two hundred and ninety-nine point nine nine nine
fifty-three
thirty-five thousand and three point one two
--Enter integer, save integer, enter decimal, if decimal point All zeros are left behind, and only one zero is left.
-- rounding ROUND( Field Name , decimal places reserved)
select Floating point number , round (floating point number, 2) rounded from floating point number;
Floating point number rounding
---------- ------------
1.0 1.0
1.1 1.1
300 300.0
1.021 1.02
1.01 1.01
100.2 100.2
0.586 0.59
299.999 300.0
53.0 53.0
35003.12 35003.12
-- rounding Keep 2 decimal places, and add a zero after the integer
select round( Floating point number , 2), LENGTH (ROUND (floating point, 2)) - LENGTH (CAST (floating point AS INTEGER)) from floating point;
Round (floating point, 2) LENGTH (ROUND (floating point, 2)) - LENGTH (CAST (floating point AS INTEGER))
------------------ ------------------------------------------------------
1.0 2
1.1 2
300.0 2
1.02 3
1.01 3
100.2 2
0.59 3
300.0 2
53.0 2
35003.12 3
0.5 2
-- rounding The length of the number of digits after subtracting the length of the number of digits after rounding is equal to 2, and a zero is required
sqlite> SELECT Floating point number AS 'raw value', (ROUND (floating point, 2)) AS' RND value ', CASE WHEN (LENGTH (ROUND (floating point, 2)) - (LENGTH (CAST (floating point AS INTEGER)))=2 THEN SUBSTR (' '| | (ROUND( Floating point number ,2))||'0', -10 , 10) ELSE SUBSTR ('' | | (ROUND (float, 2)), - 10,10) END AS' result 'FROM float;
raw value RND value result
---------- ---------- ----------
1.0 1.0 1.00
1.1 1.1 1.10
300 300.0 300.00
1.021 1.02 1.02
1.01 1.01 1.01
100.2 100.2 100.20
0.586 0.59 0.59
299.999 300.0 300.00
53.0 53.0 53.00
35003.12 35003.12 35003.12
0.5 0.5 0.50

Format Output

Announce
edit
Also called format Floating point number , refers to converting a floating point number into a specified format.
For example, there is one floating-point The number is 2.102586. When it is used to represent the number, the decimal part must be removed and formatted as 2; When it is used to express the amount, only two decimal places are reserved. Press rounding Format as 2.10 or press Progressive method Format as 2.11.
Formatting is usually required for report statistics display, data calculation and storage. Common formatting functions are: format , cast, etc.