Converting to Hex from decimal

I want to convert decimal into hexadecimal. I found some code

int num = 5;
string numResult;

numResult = num.ToString("X");

But that does not work and I get this error

Does anyone know the answer?

Greetings @Resparing

Strange… That message normally occurs when you try and convert a float to Hex. Your code works fine for me. You’ve clearly cut down the code to demonstrate the problem but are you sure that you are not passing a float in your original code? Even a float with no decimal point (eg float num = 5) would generate the same error message.