Delete str2num.h

This commit is contained in:
Valk Richard Li 2019-08-05 23:20:53 +08:00 committed by GitHub
parent 5adc681f79
commit b19761e36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 60 deletions

View File

@ -1,60 +0,0 @@
#ifndef __STR2NUM_H__
#define __STR2NUM_H__
#include <iostream>
#include <cstring>
namespace nasal
{
void Str2Num(std::string &str)
{
for(int i=0;i<(int)str.length();++i)
if(!(('0'<=str[i]) && (str[i]<='9') || (str[i]=='.')))
{
std::cout<<"[Error] Non-numeric string."<<std::endl;
return;
}
bool isFloat=false;
int DotPlace=0;
for(int i=0;i<(int)str.length();++i)
if(str[i]=='.')
{
isFloat=true;
DotPlace=i;
break;
}
if(!isFloat)
{
long long int num=0;
long long int acc=1;
for(int i=(int)str.length()-1;i>=0;--i)
{
num+=acc*((long long int)(str[i]-'0'));
acc*=10;
}
std::cout<<num<<std::endl;
}
else
{
double num=0;
double acc=1;
double aff=0.1;
for(int i=DotPlace+1;i<(int)str.length();++i)
{
num+=aff*((double)(str[i]-'0'));
aff*=0.1;
}
for(int i=DotPlace-1;i>=0;--i)
{
num+=acc*((double)(str[i]-'0'));
acc*=10;
}
std::cout<<num<<std::endl;
}
return;
}
}
#endif