1

I'm currently learning "numeric" data type on MSDN and have encountered the following phrase.

Converting from decimal or numeric to float or real can cause some loss of precision. Converting from int, smallint, tinyint, float, real, money, or smallmoney to either decimal or numeric can cause overflow.

I dont really understand the reason behind loss of precision/overflow when converting "decimal or numeric" data type. Could someone please explain it to me?

1
  • 1
    in simple terms, you get less digits/space to represent your number Commented Mar 8, 2017 at 11:50

3 Answers 3

1

Each different type of numerical representation has a different amount it can store in memory. A simple example would be using int and tinyint.

A tinyint has 2 Bytes of storage and so can hold a max value of 32,767. An int has 4 Bytes an so can hold a max value of 2,147,483,647.

If you try and convert an int into a tinyint, and the value of the int is greater than the limit of the tinyint (> 32,767) then you will run into issues. Some languages will wrap round, others will overflow.

Sign up to request clarification or add additional context in comments.

Comments

1

The documentation covers it clearly.

Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly.

Floating numbers in .NET or any framework are going to be approximate-number data types.

Comments

1

Decimal or Numeric data types are in fact integer with decimal separator position. They can store each value between min and max values, regarding declared precision. As Ryan said, you can store approx 64k different values within four bytes ranging from -32k to 32k. If you make a four bytes float type, the range would be much wider, but there are still 64k different values to be stored. Some of the values within the range are impossible to be stored precisely.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.