lexical_cast and float

Hi! I use this code to control if a sdt::string is a "float" value: string value("3.14"); try { lexical_cast<float>(value); } catch(bad_lexical_cast& ) { cout<<value<<" is not a float number\n"; } I always obtain a bad_lexical_cast exception. Why? -- View this message in context: http://boost.2283326.n4.nabble.com/lexical-cast-and-float-tp3609634p3609634.... Sent from the Boost - Users mailing list archive at Nabble.com.

I use this code to control if a sdt::string is a "float" value:
string value("3.14"); try { lexical_cast<float>(value); } catch(bad_lexical_cast& ) { cout<<value<<" is not a float number\n"; }
I always obtain a bad_lexical_cast exception.
Perhaps, your locale requires comma as fp: "3,14"

Thanks! :-) -- View this message in context: http://boost.2283326.n4.nabble.com/lexical-cast-and-float-tp3609634p3609835.... Sent from the Boost - Users mailing list archive at Nabble.com.

Hi, On Sun, Jun 19, 2011 at 10:56 PM, Igor R <boost.lists@gmail.com> wrote:
string value("3.14"); try { lexical_cast<float>(value); } catch(bad_lexical_cast& ) { cout<<value<<" is not a float number\n"; } I always obtain a bad_lexical_cast exception.
Perhaps, your locale requires comma as fp: "3,14"
But what if one did want to convert from "3.14" instead of "3,14"? How can one specify the customization in this case? Best regards, Asif
participants (3)
-
asif saeed
-
Claude
-
Igor R