Solved

stripping a double

Posted on 2002-03-24
2
223 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IdTCPClient1->Disconnect(); not working 3 77
sorting efficency of sorting algorithm 30 121
Microsoft C++ code failing in executable that worked 9 110
How do i run a c++ file? 15 46
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

829 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