Asked by Thar
on 1 Dec 2015

Hi all!

I have two matrices. They have one column. First matrix is:

7.551119

7.551154

7.551189

7.551224

Second matrix is:

7.551111

7.551146

7.551181

7.551215

I want to comparison two columns but only 5 decimal places. I don't like round my numbers like:

7.55112

7.55115

and so on, if I use the function round.

Answer by arich82
on 2 Dec 2015

Accepted Answer

You can truncate (without rounding) using floor (or fix, if your numbers can be negative):

x = [ ...

7.551119; ...

7.551154; ...

7.551189; ...

7.551224; ...

];

y = fix(x*1e5)/1e5;

output:

y =

7.551110000000000

7.551150000000000

7.551180000000000

7.551220000000000

Answer by Image Analyst
on 2 Dec 2015

Sign in to comment.

Answer by Thorsten
on 2 Dec 2015

Edited by Thorsten
on 2 Dec 2015

You can round to 5 decimal places using

xr = round(x*1e5)/1e5;

You may want to set

format long

such that the result is properly displayed.

Thar
on 2 Dec 2015

Image Analyst
on 2 Dec 2015

Walter Roberson
on 2 Dec 2015

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Walter Roberson (view profile)

Direct link to this comment:https://ch.mathworks.com/matlabcentral/answers/258463-how-to-comparison-decimal-numbers#comment_326927

## Thar (view profile)

Direct link to this comment:https://ch.mathworks.com/matlabcentral/answers/258463-how-to-comparison-decimal-numbers#comment_327089

Sign in to comment.