How to cut digits after the decimal point?
Show older comments
Hello, I have the following variable:
a1 = 0.1234
I want to cut all digits after the first one after the decimal point. Meaning:
a2 = 0.1
I've created the following code (q=1 in our example):
b1 = a1 .* 10^q;
b2 = floor(b1);
a2 = b2 ./ (10^q);
But, it output
a2 = 0.1000
How can I get rid of the zeros in the end?
Thank you.
Accepted Answer
More Answers (1)
a2 = round( a1, 1 );
if you have a sufficiently recent version of Matlab. I can't remember when this functionality was added to the round function though.
Categories
Find more on Creating and Concatenating Matrices 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!