kleine Änderung
This commit is contained in:
parent
77c915ada1
commit
cbd9cd67c0
1 changed files with 28 additions and 28 deletions
|
@ -1,50 +1,50 @@
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
using namespace std;
|
long double stringToFloat(const std::string& strng, bool decimalPoint)
|
||||||
long double Kommazahl(const std::string& str)
|
|
||||||
{
|
{
|
||||||
//Alternative mit stold welche in der Deklaration der Nebenfunktion zusätzlich einen Boolean benötigt,
|
/*Alternative mit stold welche in der Deklaration der Nebenfunktion zusätzlich einen Boolean "Komma" benötigt,
|
||||||
//welcher angibt ob es mt oder ohne Kommas arbeiten soll
|
welcher angibt ob es mt oder ohne Kommas arbeiten soll
|
||||||
|
|
||||||
/*long double Zahl;
|
long double number;
|
||||||
bool Minus = false;
|
bool minus = false;
|
||||||
std::string::size_type idx;
|
std::string::size_type idx;
|
||||||
std::string FNum = "";
|
std::string FNum = "";
|
||||||
|
|
||||||
for(char c:str)
|
for(char c:str)
|
||||||
{
|
{
|
||||||
if(c>='0' && c<='9') FNum += c;
|
if(c>='0' && c<='9') FNum += c;
|
||||||
else if(c == '-') Minus = true;
|
else if(c == '-') minus = true;
|
||||||
else if((c=='.' || c==',') && Komma) Komma = false, FNum += c;
|
else if((c=='.' || c==',') && decimalPoint) decimalPoint = false, FNum += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zahl = std::stold(FNum,&idx);
|
number = std::stold(FNum, &idx);
|
||||||
if(Minus) Zahl*=-1;
|
|
||||||
return(Zahl);*/
|
|
||||||
|
|
||||||
bool Komma=false, Minus=false;
|
if(minus) Zahl*=-1;
|
||||||
long double Zahl = 0;
|
|
||||||
unsigned short Stelle = 0;
|
return(number);*/
|
||||||
for(char c : str)
|
|
||||||
|
bool DP = false;
|
||||||
|
long double number;
|
||||||
|
unsigned short place = 0;
|
||||||
|
|
||||||
|
for(char c : strng)
|
||||||
{
|
{
|
||||||
if(c>='0' && c<='9')
|
if(c>='0' && c<='9')
|
||||||
{
|
{
|
||||||
if(Komma == false)
|
c = c-'0';
|
||||||
{
|
|
||||||
Zahl *= 10;
|
if(!DP) number = number*10+c;
|
||||||
Zahl += c - '0';
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long double Zahl2 = c - '0';
|
long double number2 = c;
|
||||||
for(unsigned short idx = 0; idx <= Stelle; idx++) Zahl2/=10;
|
|
||||||
Zahl += Zahl2;
|
for(unsigned short loop = 0; loop<=place; loop++) number2 /= 10;
|
||||||
Stelle++;
|
|
||||||
|
number += number2, place++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(c=='.') Komma=true;
|
else if((c=='.' || c==',') && decimalPoint) DP=true;
|
||||||
else if(c=='-') Minus=true;
|
|
||||||
}
|
}
|
||||||
if(Minus==true) Zahl*=-1;
|
|
||||||
return(Zahl);
|
return(number);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue