今天工作中遇到一个要不一个double型的字符串转换成一个纯字数字符串和一个标志这个数字字符串的小数点有几位的int类型
例如:“23.123”---》“23123” + 3 比较简单。就是把代码贴这里,以后用到了,可以直接拽来用
#include "stdafx.h" #include <stdlib.h>
#include <iostream>
#include <string> void getInfo(const char* pNum)
{ if (strlen(pNum) == )
{
return;
} char num[]={};
int index = ;
int decemal = ;
bool bIsDecemal = false; //遍历字符串如果找到.的话不存储. 但是decimal开始计数 for(int i = ; 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"; //目标12.232--》12232+3的格式
getInfo( num.c_str() );
getchar();
return ;
}