user4356526
user4356526

Reputation:

How to round off number in MATLAB to desired decimal points?

I want to round of 23.456 as 23.5 how to do this.

I could not find any specific function for this in MATLAB.

Upvotes: 0

Views: 1561

Answers (1)

dsbisht
dsbisht

Reputation: 1035

Here you go

Loki=[13.47471556 12.36547 21.0; 45.31 54.326 456.23; 12.2 45.14 65.39]
Ndecimals = 1 ;  
Thor = 10.^Ndecimals ;
Loki = round(Thor*Loki)/Thor

See the round off Loki

Loki (default)
   13.4747   12.3655   21.0000
   45.3100   54.3260  456.2300
   12.2000   45.1400   65.3900


Loki (round off)
   13.5000   12.4000   21.0000
   45.3000   54.3000  456.2000
   12.2000   45.1000   65.4000

Upvotes: 3

Related Questions