MATLAB: Do I receive an error when using the DEC2HEX function in MATLAB

MATLAB

If I run the following code:
a = 12.0001;
b = dec2hex(a);
I receive the following error message:
??? Error using ==> dec2hex at 27
First argument must contain non-negative integers.

Best Answer

The DEC2HEX function throws this error if the input arguments are floating point numbers and not integers as expected.
A workaround for this issue would be to use the FIX command to make sure that the number being passed to DEC2HEX is an integer. For example:
dec2hex(fix(arg))
This may also be achieved by type-casting the number appropriately before passing it to DEC2HEX. For example:
dec2hex(int32(temp))