#include <iostream>
using namespace std;
double toFPV(char str[]);
int main(){
char numstr [100]= "22.14429789";
cout<<toFPV(numstr);
return 0;
}
double toFPV(char str[]){
int i = 0;
double whole = 0;
double frac = 0;
int div = 1;
double num;
while(str[i]!='.'){
whole *= 10;
whole += str[i] - '0';
i++;
}
i++;
while(str[i]!='\0'){
frac *= 10;
frac += str[i]-'0';
div *= 10;
i++;
}
frac /= div;
num = whole + frac;
return num;
}
I'm trying to learn character arrays but I can't figure out what I'm doing wrong. The function toFPV is supposed to convert the character array to a Floating point value but it keeps rounding off the number to four decimal places instead of showing the rest of numbers in the array.