The double type string is converted to a pure numeric string and a C + + code with a decimal point number

Source: Internet
Author: User

Today's work encounters a string that is either a double character string and a flag that has several int types in the decimal point of the numeric string

For example: "23.123"---"23123" + 3 is relatively simple. is to put the code here, later used, can be directly dragged to use

#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;

The variable string is not stored if it is found. But decimal starts counting.

for (int i = 0; Pnum[i]! = ' + '; 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"; The format of the target 12.232--"12232+3"
GetInfo (Num.c_str ());
GetChar ();
return 0;
}

The double type string is converted to a pure numeric string and a C + + code with a decimal point number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.