double类型字符串转换成一个纯数字字符串和一个小数点位数的c++代码

今天工作中遇到一个要不一个double型的字符串转换成一个纯字数字符串和一个标志这个数字字符串的小数点有几位的int类型

例如:“23.123”---》“23123” + 3   比较简单。就是把代码贴这里,以后用到了,可以直接拽来用

 1 #include "stdafx.h"
 2 
 3 #include <stdlib.h>
 4 #include <iostream>
 5 #include <string>
 6 
 7 void getInfo(const char* pNum)
 8 {
 9 
10     if (strlen(pNum) == 0 ) 
11      {
12           return;
13     }
14 
15     char num[100]={0};
16     int index = 0;
17     int decemal = 0;
18     bool bIsDecemal = false;
19 
20 //遍历字符串如果找到.的话不存储. 但是decimal开始计数
21 
22     for(int i = 0; pNum[i] != ''; i++ )
23     {
24             if(pNum[i] == '.')  
25             {
26                 bIsDecemal = true;
27                 continue;
28             }
29 
30             num[index] = pNum[i];
31             index++;
32 
33             if( bIsDecemal)
34             {
35                 decemal++;
36              }
37     }
38 
39     std::cout<<num<<"----"<<decemal<<std::endl;
40 }
41 
42 int _tmain(int argc, _TCHAR* argv[])
43 {
44 std::string num = "12.232"; //目标12.232--》12232+3的格式
45 getInfo( num.c_str() );
46 getchar();
47 return 0;
48 }                        
原文地址:https://www.cnblogs.com/silentNight/p/5266776.html