Works on this device
Decimal Precision Calculator
See how precise a decimal number is: how many decimal places and digits it has, and what step size that means. You can compare two numbers to a tolerance, and you can see the exact binary floating-point value that a computer stores for a decimal such as 0.1.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose the button below them.
Your result
How it was worked out
Decode an IEEE 754 bit pattern
Choose Decode IEEE 754, then enter eight hexadecimal digits for single precision or sixteen for double precision. A full 32-bit or 64-bit binary string also works. The result preserves negative zero, subnormal values, infinities and the payload of a NaN.
For two 16-bit device registers, enter the unsigned words in their received order and select the byte layout specified by the device manufacturer.
How to use this calculator
- Choose what you want to find.
- Type the number with all its digits. Zeros at the end count here:
2.50has two decimal places. - Choose the button under the form. Every result is worked out exactly from the digits you typed.
What the words mean
- Decimal places (also called scale): the number of digits after the decimal point. 123.4500 has 4.
- Precision: the number of digits in total, not counting zeros in front. 123.4500 has 7 and 0.0045 has 2.
- Step size (also called resolution): the smallest change that can be written with a number of decimal places. With 2 decimal places the step is 0.01. Formula: step = 10 to the power of minus the decimal places.
- A number given to a step can be up to half a step away from the true value. 2.50 stands for any value from 2.495 to 2.505.
- Step to decimal places: write the step as a fraction in lowest terms. If the bottom number has only the prime factors 2 and 5, the larger of their powers is the number of decimal places needed. A step of 0.25 is 1/4 = 1/2², so it needs 2 places. A step of 1/3 never ends as a decimal.
- A database column of type DECIMAL(p, s) holds p digits in total, with s of them after the point.
Decimals in a computer
Most programs store numbers in binary floating point, as described by the standard IEEE 754. A double has 53 binary digits. Most decimals, such as 0.1, do not end in binary, just as 1/3 does not end in decimal. The computer stores the nearest value it can.
The floating-point option works out that stored value exactly, with whole-number arithmetic, and shows its bits and the rounding error. This is why 0.1 + 0.2 is not exactly 0.3 in many programs.
Worked examples
123.4500 has 4 decimal places and 7 digits in total, so it fits the type DECIMAL(7, 4). Its step size is 0.0001.
A step of 0.25 needs 2 decimal places. A step of 1/8 = 0.125 needs 3. From 0 to 1 in steps of 0.25 there are 5 values.
3.14159 and 3.14162 differ by 0.00003. They are equal within an absolute tolerance of 0.0001, and their first 3 decimal places have the same digits.
The double nearest to 0.1 is exactly 0.1000000000000000055511151231257827021181583404541015625. The rounding error is about 5.55 × 10^-18. Its bit pattern is 3FB999999999999A in hexadecimal.
0.5 is stored exactly, because it is 1/2.
Limits you should know
- A typed number can have at most 60 characters. Exponents such as 1e-7 are allowed.
- The comparison counts matching digits without rounding. Two close numbers such as 0.9999 and 1.0001 have no matching digits.
- The floating-point option covers two formats: binary64 (double) and binary32 (single). It shows one stored number. It does not follow the rounding of a whole calculation.
- A number that is too large for the format gives an error message. A number that is too close to zero is stored as 0, and the page says so.
- The DECIMAL(p, s) result follows the usual meaning of precision and scale in SQL. Database systems have their own upper limits for p.