Solved

stripping a double

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

832 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