424,972 Members | 1,115 Online Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

how to find if a number contains a decimal

 P: 4 is there a way to find a decimal in a umber similar to str\$ in VB Jun 15 '07 #1
7 Replies

 Expert 100+ P: 1,275 is there a way to find a decimal in a umber similar to str\$ in VB r u asking how can we find whether the nuber is an integer or float? Is my assumption right Raghu Jun 15 '07 #2

 P: 4 no..i'm doing some math calculations and need to ..i think.. convert the results to a string or char so i can determine if there is a decimal point int the math result..maybe it can be done someway else??? Jun 15 '07 #3

 Expert 100+ P: 1,275 no..i'm doing some math calculations and need to ..i think.. convert the results to a string or char so i can determine if there is a decimal point int the math result..maybe it can be done someway else??? If u are doing a math calculation then why ar u converting it to string. If u think the math expression may give decimal then always use a float/double to store the values and convert it to int when needed. My suggestion is dont convert the output to string and convert it back to intger or float. Raghuram Jun 15 '07 #4

 Expert 100+ P: 1,764 no..i'm doing some math calculations and need to ..i think.. convert the results to a string or char so i can determine if there is a decimal point int the math result..maybe it can be done someway else??? I don't understand what are you trying to do.Can you give as a small example? Savage Jun 15 '07 #5

 P: 4 i need to determine if a division result is a whole number or has a decimal in it. Jun 15 '07 #6

 Expert 100+ P: 844 i need to determine if a division result is a whole number or has a decimal in it. I think the modulo operator might work: Expand|Select|Wrap|Line Numbers int num1 = 24; int num2 = 6;   if (!(num1 % num2))      // the numbers divide evenly {     cout << "The result is a whole number." << endl; } else {     cout << "The result has a decimal in it." << endl; }   Jun 15 '07 #7

 Expert Mod 5K+ P: 9,197 Use a stringstream. Expand|Select|Wrap|Line Numbers double d = 1.2345; stringstream ss; string str;   ss << d; ss >> str;   Now you can locate the decimal point inside the string usingfind(). Jun 15 '07 #8 