Reputation: 179
How can I round a decimal number like 26,548746540516
to 26,5487
in MATLAB?
Upvotes: 4
Views: 26210
Reputation: 6579
You can use round
as follows
round(x*10000) / 10000.0
Alternatively, you can use round2
round2(x,0.0001)
round2(x,1e-4)
Upvotes: 8
Reputation: 526
If it's purely display, you could also try sprintf() with formatted output. The syntax for what you want would be sprintf('%.4f',26.548746540516);
You can see where you would need to change the number to a variable, and can easily change how many numbers after the decimal show up(before as well using %2.4f, for example).
Upvotes: 2