How to display outputs in a certain decimal value

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

fprintf('%d\n', x);

4 Comments

That is the command, thank you very much!
Now how would I make this then say, 3000 lb instead of just 3000? Sorry, I do not use Matlab often enough to remember these things.
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..
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

Community Treasure Hunt

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

Start Hunting!