Solved

stripping a double

Posted on 2002-03-24
2
219 Views
Last Modified: 2010-04-02
what would be the easiest way to strip the whole number of the double....ie.

37.39283

to the value of 39283

I just need to get the fraction out of it, I thought it would be simple at first by
double x = 37.39283;
double y;

y = (x % 1);

but doh......only can use that for integers.  Any other simple suggestions?


0
Comment
Question by:boodabelly
2 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 100 total points
ID: 6893089
what about

y =  x - (int)x;
0
 
LVL 1

Author Comment

by:boodabelly
ID: 6893105
well damn I am dumb.......this is what I just did, but hell.....its been to long since I have done this :(.

     memset(buffer, 0, 64);
     sprintf(buffer, "%f", x);

     if(!buffer)
     {
          return;
     }

     decimalPlace = strstr(buffer, ".");          // search for the decimal point

     decimalPlace++;                                   // advance past decimal point
     y = (double)strtol(decimalPlace, 0,10);

I think I will be using your's thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now