Reputation: 275
I have a very simple code where I get a value from numeric updown which I have then to convert to hex. (for numericupdown Hexadecimal
property is set true)
I select FF
from nud located in winForm. then in code
string str = nudID.Value.ToString("X");
But this is not working and I am getting format exception
Upvotes: 0
Views: 265
Reputation: 23935
this should work:
string str = ((int)nudID.Value).ToString("X");
You need to parse the decimal value to int. You can make it a bit safer by using TryParse if you want to.
Upvotes: 0
Reputation: 7202
NumericUpDown.Value
returns Decimal
. Decimal.ToString(string)
does not support "X":
The format parameter can be any valid standard numeric format specifier except for D, R, and X
Adapting some code from this solution, try this if you are on .NET 4.0 or later:
string str = new System.Numerics.BigInteger(nudID.Value).ToString("X");
Upvotes: 3
Reputation: 3451
NumericUpDown value isn't Int type, it's Decimal. Maybe here is the problem?
Upvotes: 4