Home > Back-end >  Data type double to a float variable, with the principle of data truncation
Data type double to a float variable, with the principle of data truncation

Time:10-07

Those seven significant figures after the wrong number is how to?

CodePudding user response:

That is not a mistake, it is not accurate expression

Effective digital only 6 ~ 7 float, double valid number is 15 ~ 16

Floating-point and integer, integer within the scope of the integer expression every digital accurately express
Floating point is you can see that as a result, 1234567890, the float before six is a valid number, is behind the approximate number

This is not the truncation

CodePudding user response:

Do you think about the number of binary representation
Before the decimal point each said 1 2 4 August 16
After the decimal point, each said 0.5 0.25, 0.125, 0.0625, 0.03125,...
Digital limited, unable to express each decimal precision, can only be approximate

CodePudding user response:

Float precision is not enough, commissioning tests is to know

CodePudding user response:

With %. 20 f show 2.2-2.1 is not equal to 0.1, computer hardware, programming languages can do ah,

CodePudding user response:

Can have a look at my early wrote a blog
https://blog.csdn.net/happy__888/article/details/277587
Float in accordance with the provisions of the IEEE format said the decimal part of 23 bits
Means that only 2 ^ 23 floating-point number can be accurate, says in addition are only approximate the
2 ^ 23 seems to be very big, but in fact it is in the middle of a rational part, irrational number and rational number has not been an order of magnitude, far more than rational number

CodePudding user response:

Fun
reference 1 floor response:
that is not a mistake, can't be accurate expression

Effective digital only 6 ~ 7 float, double valid number is 15 ~ 16

Floating-point and integer, integer within the scope of the integer expression every digital accurately express
Floating point is you can see that as a result, 1234567890, the float before six is a valid number, is behind the approximate number

This is not truncated

The truncation is what circumstance?
On this subject can know, from which the book seems to be no,

CodePudding user response:

Truncation is int n=1.234;
This is truncated, the decimal point are cut out

This kind of knowledge and some books, look at the number of binary representation, may not have said so fine, but will mention about the representation of a float type range and effective digital
Programming books, and other different is that, in addition to the book all demonstration code, and other places are key
Code is used to explain what the text description instead, is to let you understand what the words
But beginners tend to ignore it, staring into the demonstration code, only the wrong direction!

CodePudding user response:

Fun
reference 7 floor response:
truncation is int n=1.234;
This is truncated, the decimal point are cut out

This kind of knowledge and some books, look at the number of binary representation, may not have said so fine, but will mention about the representation of a float type range and effective digital
Programming books, and other different is that, in addition to the book all demonstration code, and other places are key
Code is used to explain what the text description instead, is to let you understand what the words
But beginners tend to ignore this, just staring at demonstration code, that is wrong direction

Educated, thank??
  • Related