Boost logo

Boost :

From: Philippe Vaucher (philippe.vaucher_at_[hidden])
Date: 2006-06-29 09:08:27


>
> Is there anything in Boost which I can use to convert a more descriptive
> string like "60%" to a double?
>

The real answer is I don't know but maybe something like the following
should do:

double str_to_double(const std::string& s)
{
    assert(!s.empty());
    if(str[str.size() - 1] == '%')
      return str_to_double(s.substr(0, s.size() - 2));
    return boost::lexical_cast<double>(s) / 100.0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk