Convert a string of the double type into a pure numeric string and a c ++ code with the decimal point. double decimal point
In today's work, I encountered a string that is not double type converted into a pure word string and a number of int types that indicate the decimal point of this numeric string.
For example, "23.123" --- "23123" + 3 is relatively simple. It is to paste the code here and use it later. You can use it directly.
# Include "stdafx. h"
# Include <stdlib. h>
# Include <iostream>
# Include <string>
Void getInfo (const char * pNum)
{
If (strlen (pNum) = 0)
{
Return;
}
Char num [100] = {0 };
Int index = 0;
Int decemal = 0;
Bool bIsDecemal = false;
// If the variable string is found, it is not stored. But the count starts from decimal.
For (int I = 0; pNum [I]! = '\ 0'; I ++)
{
If (pNum [I] = '.')
{
BIsDecemal = true;
Continue;
}
Num [index] = pNum [I];
Index ++;
If (bIsDecemal)
{
Decemal ++;
}
}
Std: cout <num <"----" <decemal <std: endl;
}
Int _ tmain (int argc, _ TCHAR * argv [])
{
Std: string num = "12.232"; // target 12.232 -- "12232 + 3 Format
GetInfo (num. c_str ());
Getchar ();
Return 0;
}