Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Maintaining float precision string parsing

$
0
0

@opseidon wrote:

Hi,

So I have a project where I’m parsing lots of floats from a csv with the great ofxCsv addon.

Once I have my numbers as std::string, ex: “-706482,4243618”, the floats are formatted with a comma separator.

I have a simple function that replaces the comma with a dot. i.e.,

float formatNum(const string & s){
	float ret = -1;
	size_t pos = s.find(",");
	if(pos == s.npos){ cout << "no dot formatNum"; return ret; }

	string numstr = s;
	numstr.replace(pos, 1, ".");

	return ofToFloat(numstr);
}

The number this function outputs is something like -70648.4243

Do you have an idea to get the full number on the string instead of this truncated working example?

Thanks

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles