943,850 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 659
  • C++ RSS
Sep 10th, 2008
0

seperating a decimal

Expand Post »
How would one seperate a decimal into 2 numbers, the left and right sides of the decimal?

float example = 131.14567

into...

int left = 131
float right = .14567

thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Nemoticchigga is offline Offline
98 posts
since Feb 2008
Sep 10th, 2008
0

Re: seperating a decimal

Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 10th, 2008
0

Re: seperating a decimal

One option is something like:

  1. float in = 131.14567f;
  2. int left = (int)in;
  3. float right = left - in;
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is online now Online
4,132 posts
since Oct 2006
Sep 10th, 2008
0

Re: seperating a decimal

Or may be convert the double into string. Then split the string using "." as the delimiter??
Reputation Points: 37
Solved Threads: 7
Junior Poster
raul15791 is offline Offline
102 posts
since Jun 2008
Sep 10th, 2008
0

Re: seperating a decimal

Stop indulge in fantasies. See iamthwee's exhaustive answer...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: priority queue ordering
Next Thread in C++ Forum Timeline: How to integrate a program into a win32 app?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC