Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert float into char in c language?
How to convert float into char in c language?
You can use a cast, the general form of which is: (type descriptor) (expression), and its function is to cast the operation result of the expression to the type indicated by the type descriptor. For example, (float) a converts a to a floating-point type, and (int)(x+y) converts the result of x+y to an integer type.

This method will obviously affect the accuracy of floating-point data, and pay attention to the different forms of final output, and the results will be different. If you want to keep the digital output, it will be in %d format.

Application examples in the program:

Note that different output formats correspond to different outputs.

Extended data:

When using cast, you should pay attention to the following issues:

1. Type specifiers and expressions must be enclosed in parentheses (individual variables can be enclosed without parentheses). For example, writing (int)(x+y) as (int)x+y is equivalent to converting x into int and then adding it to y. ..

2. Whether forced conversion or automatic conversion, the data length of the variable is temporarily converted for the needs of this operation, and the type defined for the variable during data description is not changed.

Baidu Encyclopedia -C language type forced conversion