A floating point number is converted in the specified format
This entry is missingOverview, add relevant content to make the entry more complete, and it can also be upgraded quickly. Hurry upeditCome on!
Normalized floating point numbers, also known as formatted output, refer toFloating point numberConvert 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
If notFloating point numberThe representation of the same floating point number is not unique.For example,Decimal numberIt can be expressed as 1.11 × 10zero,0.111×10one,0.0111×10twoAnd other forms.To improve the precision of data representation, whenMantissaWhen the value of is not 0, the most significant bit of the mantissa field should be 1, which is called theNormalizationexpress.Otherwise, modifyOrder codeMove left and right at the same timedecimal pointPosition the method to make it into the form of normalized number.
But inIEEE754 standardThe 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 fieldSignificant bitTo 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 bitFloating point numberThe 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
WhenOrder codeWhen 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-bitFloating point numberIn 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 representsabsolute valueThe range of is 10-38~10thirty-eight(Expressed as a power of 10).
--roundingThe 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> SELECTFloating point numberAS '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 formatFloating point number, refers to converting a floating point number into a specified format.
For example, there is onefloating-pointThe 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. PressroundingFormat as 2.10 or pressProgressive methodFormat as 2.11.
Formatting is usually required for report statistics display, data calculation and storage. Common formatting functions are:format, cast, etc.