MATLAB: Convert number to string problem

homeworkMATLABmsgboxstring

I would like to ask if there is a way to output a number, which is stored as a variable, using simple commands, as shown in the following examples:
9 is converted to: 'The number is +9.'
6.54 is converted to: 'The number is +6.54.'
-7 is converted to: 'The number is -7.'
-9.2 is converted to: 'The number is -9.2.'
0 is converted to: 'The number is 0.'
I would like to display it in the command window and a message box (msgbox).
Please help. Thanks in advance.

Best Answer

number = 10; % an example
if number>=0
sprintf('The number is : +%d',number)
else
sprintf('The number is : %d',number)
end
Assign a variable to sprintf() and then place it inside the command msgbox().