eg. Follow the steps below to convert a base 10 decimal number to 32 bit single precision IEEE 754 binary floating point: 1. Results: Decimal Value Entered: Single precision (32 bits): Binary: Status: Bit 31 Sign Bit 0: + 1: -. When the precision shows a range, like 6-8, it means one segment has 6 digits, another has 7 digits, and another has 8 digits. In any given segment, you can find examples of numbers that convert to a higher precision than supported by that segment: This is not precision, at least as we have defined it; precision is a property of a range of n-digit numbers, not a specific n-digit number. Let’s look at 1.013e-4 and its six nearest 9-digit neighbors: 1.01299997e-4 The range of exponents we may represent becomes 128 to -127. With that methodology, I came up with an average decimal precision for single-precision floating-point: 7.09 digits. So, for instance, if we are working with 8 bit numbers, it may be agreed that the binary point will be placed between the 4th and 5th bits. Converting decimal fractions to binary is no different. In this section, we'll start off by looking at how we represent fractions in binary. 89.27% of the range has 7 digits, 10.1% has 8 digits, and 0.63% has 6 digits. Indicate fractional values with a decimal point (‘.’), and do not use commas. Do you agree? 1.013e-4 converts to 1.01300000096671283245086669921875e-4, which appears to have 9 digits of precision; but it’s in an 8-digit segment. If we want to represent 1230000 in scientific notation we do the following: We may do the same in binary and this forms the foundation of our floating point number. (It’s unfortunate we have to be that conservative; only a small percentage of the float range is limited to 6 digits.) 1/3 is one of these. 1.24e-4 converts to 1.23999998322688043117523193359375e-4, which appears to have 8 digits of precision; but it’s in a 7-digit segment. 5 + 127 is 132 so our exponent becomes - 10000100, We want our exponent to be -7. Put 0.085 in single-precision format. Do you want to know the precision for one power of ten exponent? A nice side benefit of this method is that if the left most bit is a 1 then we know that it is a positive exponent and it is a large number being represented and if it is a 0 then we know the exponent is negative and it is a fraction (or small number). It is known as IEEE 754. To get around this we use a method of representing numbers called floating point. Java Doesn’t Print The Shortest Strings That Round-Trip, 17 Digits Gets You There, Once You’ve Found Your Way, “A Formalization of Floating-Point Numeric Base Conversion”, http://kurtstephens.com/files/p372-steele.pdf, https://www.exploringbinary.com/number-of-digits-required-for-round-trip-conversions/, Decimal Precision of Binary Floating-Point Numbers, Correct Decimal To Floating-Point Using Big Integers, The Spacing of Binary Floating-Point Numbers, Direct Generation of Double Rounding Error Conversions in Kotlin, Double Rounding Errors in Decimal to Double to Float Conversions, Maximum Number of Decimal Digits In Binary Floating-Point Numbers, I primarily do an analytical analysis based on relative gap sizes instead of running code to check round-trips. The 9-digits for floats comes from those who store floats in text formats. It's just something you have to keep in mind when working with floating point numbers. But you’re not getting that much decimal precision in any range of those IEEE formats. To convert from floating point back to a decimal number just perform the steps in reverse. You should get .0009765628 (does not match). Conversion to decimal is very simple if you know how these numbers are represented. I don’t analyze subnormal numbers, where the precision can go down to as low as 0 digits. It's not 0 but it is rather close and systems know to interpret it as zero exactly. Bits 0-22 (on the right) give the fraction (If you compare the power of two and power of ten gap sizes over the entire double range you can see that the first round-trip failure occurs between 2^3 and 10^1; if you start testing at 2^3 you find it right away.). Let's look at some examples. Hexadecimal Representation: Results: Decimal Value Entered: Single precision (32 bits ... [ Convert IEEE-754 64-bit Hexadecimal Representations to Decimal Floating-Point Numbers. ] With that methodology, I came up with an average decimal precision for single-precision floating-point: 7.09 digits. The average across just those two powers of two would be (7*1 + 7*0.2 + 8*0.8)/2 = 7.4. This is used to represent that something has happened which resulted in a number which may not be computed. As we move a position (or digit) to the left, the power we multiply the base (2 in binary) by increases by 1. In this case we move it 6 places to the right. You can’t get less precision than each segment supports, but you can get what looks like more. 2. The creators of the floating point standard used this to their advantage to get a little more data represented in a number. 145 10 = 10010001 2. a) That if you print with enough digits then your floats will be perfectly preserved. How is it that I can represent any digit of 7 precision in a float? Yes! Doing the same analysis for doubles I computed an average decimal precision of 15.82 digits. Double precision works exactly the same, just with more bits. In this article, I will argue that there are only three reasonable answers: “6 digits”, “6-8 digits”, and “slightly more than 7 digits on average”. 1.01300002e-4 So d-digit precision (d a positive integer) means that if we take all d-digit decimal numbers over a specified range, convert them to b-bit floating-point, and then convert them back to decimal — rounding to nearest to d digits — we will recover all of the original d-digit decimal numbers. Example: Converting to Float. There are a few special cases to consider.