MATLAB: Turn 0 to 0.000

0 to 0.000formattingformatting specified number formatMATLAB

Well this is a formatting issue, how can I force any number to have a specified format? Example:
I have 1.23, I need 1.230
I have 0, I need 0.000
I have 0.1011, I need 0.101
I have 5.1019, I need 5.102
I have 20.002, I need 20.002 (stays the same)
I seem to have tried a few methods I found on-line, however still have not found one that works exactly this way. I would never exceed 99.999 or -99.999. Thanks, Chris

Best Answer

Use sprintf():
sprintf('%.3f', 0) % to command window.
outputString = sprintf('%.3f', 5.1019) % Sticks it in a string.