Last answered:

24 Jun 2024

Posted on:

20 Jun 2024

0

Resolved: Doubt about difference between fixed-point and floating-point

Helllo ;)

I have a question regarding fixed-point and floating-point data types.


In the video, it is mentioned that if a value like 10.5236789 is entered into a field of type DECIMAL(5,3), it will be stored as 10.524. I understand it is stored this way because the field only allows for a total length of 5 digits, with 3 of them being decimals, and the number is rounded or truncated based on the configured settings (min 1:50).

However, when using another field with data type FLOAT(5,3), and entering the same number, it is also stored as 10.524. This means it also respects that the number must have a maximum length of 5 characters, with 3 of them being decimals. (min 4:24)

I don't understand when it's said that a floating-point value is approximate; in both columns, the number has not been stored exactly as it is but rather as an approximation.

I've been reading, and what I think could be an answer is that when using a floating-point, the number we input is stored as the closest binary representation, whereas a fixed-point stores the number as it is.

I hope you can help me understand this difference between data types. Perhaps my question arises from not having a background in computing.

Best regards and thank you in advance.

1 answers ( 1 marked as helpful)
Instructor
Posted on:

24 Jun 2024

1

Hi Enrique!
Thanks for reaching out.


You're on the right track with your understanding of fixed-point and floating-point data types. Here’s the key difference:

Fixed-point (e.g., DECIMAL(5,3)): This data type stores numbers as exact values to the precision defined. So, 10.5236789 is stored as 10.524 because it rounds to fit the specified format of 5 total digits with 3 after the decimal.
Floating-point (e.g., FLOAT(5,3)): This data type represents numbers in a way that can handle a very wide range of values by storing an approximation of the number. Even though 10.524 is displayed, the actual stored value might be slightly different due to the binary representation of floating-point numbers.
In both cases, the output looks similar, but floating-point types are typically used for calculations requiring a vast range of values (like scientific calculations), whereas fixed-point is used when precise, consistent values are needed, such as in financial calculations.
 


Hope this helps.
Best,
Tsvetelin

Submit an answer