convert my string so that we can put a space for every 3 digit.
Since you are starting with a string, you might consider just doing the the deed directly (no float math).
The following function takes a string and counts off 3 digits from the least significant char (the right most) and returns the digits with spaces inserted (the line grows). (it does not confirm validity of number, does not check that chars are digits)
std::string digiSpace3(std::string s)
{ // sSize must be signed int of sufficient size
int32_t sSize = static_cast<int32_t>(s.size());
if (sSize > 3)
for (int32_t indx = (sSize - 3); indx > 0; indx -= 3)
s.insert(static_cast<size_t>(indx), 1, ' ');
return(s);
}
used like:
std::string MegaNum = "10020030040" ;
// std::string MegaNum ( std::to_string(10020030040) ) ; //also works
std::cout << "\n " << digiSpace3(MegaNum) << std::endl;
and produces
10 020 030 040
fyi - my compiler does not accept
std::string MegaNum( float 10020030040 );
and reports
error: expected ‘,’ or ‘...’ before numeric constant