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 PostCreate a for-loop, that iterates through each character, and ensure their ASCII (assuming you are not working with international representations) value is numeric, a hyphen or a decimal. At the same time, make …
Jump to PostYou can also use isdigit() library function and loop through the string to check whether thy are numeric or not.
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 …
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.