Hi All,
I'm handling a code which is having signed decimal values(eg: -123.456)stored in a cheracter string.While performing numeric calculations on this field, need to check whether all digit is numeric.Can anyone help me.
Your co-operation greatly appreciated.
NB: There is strict instruction to store these values in char string.Not double/float
Remzz 0 Newbie Poster
Recommended Answers
Jump to PostAnother approach is to use the
strtod(const char* nptr, char** endptr)
function. You pass the string containing the number, and the address to a char* which will be set by the function to the first non-numeric character. FWIW,strtod()
[double] andstrtof()
[float] will also accept scientific notation, such as …
Jump to PostYou could use
boost::lexical_cast
to try and convert the string to a number and catch theboost::bad_lexical_cast
exception that's thrown if the conversion can't be done. This feels a bit weird though, as I generally try not to use exceptions for flow control. I guess you should wrap it in …
Jump to PostWon't they both simply convert whatever it can to binary and stop when an invalid character is seen?
boost::lexical_cast
will throwboost::bad_lexical_cast
if the string can't be fully converted to the kind of value that you specify. For example, the following prints "That's not a valid …
All 9 Replies
nmaillet 97 Posting Whiz in Training
np complete 8 Newbie Poster
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
ravenous 266 Posting Pro in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
ravenous 266 Posting Pro in Training
Remzz 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.