0

Hi,

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

3
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by NathanOliver
0

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?

0

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

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

    }
}

Edited by Nick Evan: Fixed formatting

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.