Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - VC++ compile time prompts truncation from "double" to "float". What does "truncation" mean?
VC++ compile time prompts truncation from "double" to "float". What does "truncation" mean?

In the current computer, double type storage occupies 8 bytes, and float type storage occupies 4 bytes. When two different types of data are assigned, the system performs implicit type conversion, and high-precision When assigning low-precision values, low-precision variables cannot completely store high-precision data. The system will automatically "truncate" part of the content to complete the data transfer, which may cause data accuracy to be lost.

In the C/C++ language, the default type of floating-point constants is double type, such as 0.5, 123.45, etc.

If you want to get a float type constant, you need to add f after the constant Characters, such as: 0.5f, 123.45f, etc.

When assigning double type data to a float type variable, the system will report the following warning during compilation:

warning C4244: '=' : conversion from 'double' to 'float', possible loss of data (conversion from double to float may cause data loss)

Therefore, the assignment between data must be of the correct type. It is recommended to use For floating point numbers, only use the double type.