I am required to convert an Array Type DOUBLE to INT, for ease of plotting a graph.
Fairly new to programming and unsure how to go about this. Any ideas appreciated

Recommended Answers

All 4 Replies

I think you need to provide a little more information about your intentions.

Are you trying to plot just the integer part of a floating-point value (i.e. if you have 3.14, you want just the 3) or do you want to convert a value such as 3.1415 to 31,415?

thanks for responding back so quickly.

yes I am just trying to plot the floating part, as you said plot 3 instead of 3.14
I have added .5 to each of the double values in the array in order to round to the nearest integer

void ConvertArray (double OldArray[], int NewArray[])
    for(int i = 0; i < 60; i ++)
        OldArray[i] = OldArray[i] + .5;
        NewArray[i] = OldArray[i];


Do you want to round the number? Like 3.7 becomes 4 but 3.2 becomes 3 or do you just want to drop the decimal part? If you just want to drop the decimal part you could do

double doubleArray[60];
int intArray[60];
for (int i = 0; i < 60; i++)
    intArray[i] = doubleArray[i];

If you want to round your number check this out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.