int n;
Judge whether the > 0 save flag bit defaults to'+'.
Build a character stack,
Absolute value of n
Do-while loop, the loop body is executed at least once, and the termination condition is n=0.
{
N The remainder divisible by 10 is put on the stack, and n = n/10;
}
Get string
{
Sign bits saved between judgments. If it is-,it is stored in a string, and if it is+,it does not need to be stored.
The principle of LIFO is to take out the stack and put the strings in turn.
}
The result string is the result.
Double transformation
Double n;
Get the integer part, and use integer to process the conversion (of course, if you use (int)n here, it may overflow and need extra processing) to get the integer part string.
Get the decimal part and build a character array (long enough)
Jud whether that fractional part is zero,
If it is zero, the length of the fractional part string is 0, that is, the 1 th character of the fractional part character array is assigned to' \0'.
If it is not 0
{
The first character is saved as the decimal character "."
In the loop, the fractional part of the termination condition is equal to 0.
{
Decimal part * 10, take out the integer part and put it into the character array, even if it is 0,
Continue to truncate the decimal part
}
}
Concatenates the integer part string with the decimal part string to obtain the result.
The code is more troublesome to write.