Converting Double to String: Preserving the Last Digit

  • Context: MATLAB 
  • Thread starter Thread starter NoobixCube
  • Start date Start date
  • Tags Tags
    String
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 11K views
NoobixCube
Messages
154
Reaction score
0
Hi all,
I am converting a double to a string. But in the following case:
-----------
format long
numnum=546.790;
num=num2str(numnum)
length(num)
---------------
when 'numnum' is converted to a string, the command truncates the number by leaving off the last digit, the zero. Is there a way to keep the zero on there when converting to a string?
 
Physics news on Phys.org
Yes, specify the format as a floating point number
num2str(numnum,'%3.3f')
or use one of the other formats (scientific notation, etc.) listed in the Help manual. Check the Help entry for num2str and you'll see a clickable link to the format list.