Convert double to int

using Gadgeteer.Modules.GHIElectronics;

namespace ledcontroller2
{
    public partial class Program
    {
        int a;
        int b = 1000;
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            double x = joystick.GetJoystickPosition().X;
            Debug.Print("X = " + x);
            if (x > 0.05)
            Convert.ToInt32(x);
            {
             a = x * b;
            }
            led7r.Animate(a, true, true, false);
        }
    }
}

Somehow [quote]a = x * b;[/quote] just wont work, i also tried to convert x ( [quote]Convert.ToInt32(x);[/quote])
Maybe the mistake is obvious and stupid, but i would be glad if u could help me :slight_smile:

@ andre.m -
i already tried that
Doesn’t work for me either …

That’s because you already declared “a” as an int and then tried to do it again.

using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace ledcontroller2
{
    public partial class Program
    {
        int b = 1000;
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            double x = joystick.GetJoystickPosition().X;
            Debug.Print("X = " + x);
            int a = (int)x;
            if (x > 0.05)
            {
                a = x * b;
                led7r.Animate(a, true, true, false);
            }
        }
    }
}

Still not working

Thats why I tought I’d try to convert x to int.
You gotta know that im very new into c# and programming in general :wink:
Using it for not quite 3 days now.

Or to keep the precision of x in multiplication you could do

a = (int)(x * b);
1 Like