Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# stripping a double

Posted on 2002-03-24
Medium Priority
230 Views
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
Question by:boodabelly

LVL 3

Accepted Solution

GGRUNDY earned 400 total points
ID: 6893089

y =  x - (int)x;
0

LVL 1

Author Comment

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

Question has a verified solution.

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

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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
###### Suggested Courses
Course of the Month12 days, 12 hours left to enroll