How to display outputs in a certain decimal value

8 views (last 30 days)
I have an output that I am trying to display. For example, when I do display(x) it shows it as 3.0+003, but i need it to display 3000. How would I do this? I know I have done this before, but I can't seem to find my old program where I did it. Thanks

Accepted Answer

Image Analyst
Image Analyst on 7 Mar 2012
fprintf('%d\n', x);
  4 Comments
Shameer Parmar
Shameer Parmar on 8 Dec 2014
Store your result to some output variable say 'output'
So when output = 3000
convert it to string format using command num2str
output = num2str(output);
now concatenate your output value with string ' lb' i.e
output = strcat(output, ' lb');
so the final value of variable will be '3000 lb'
Hope this will work for you..
Image Analyst
Image Analyst on 8 Dec 2014
x=3000;
fprintf('%d lb\n', x);
or, to get a string variable
str = sprintf('%d lb', x);

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!