After a calculation I got 32.073 .I need it to round to 32.07 using Octave.Please can somebody help me?
Asked
Active
Viewed 1.8k times
9
-
did you try searching the web? – Display Name Jul 11 '14 at 09:50
-
Of course.No proper way to be found. – AnoAPI Jul 11 '14 at 09:56
-
You didn't specify if you need the rounded number or just printing it. The answer depends on this. – sancho.s ReinstateMonicaCellio Aug 09 '20 at 22:51
3 Answers
7
You can do:
res = round(100 * 37.073) / 100

Jean Logeart
- 52,687
- 11
- 83
- 118
-
1
-
@AnoAPI you cannot. You either have a floating point like that or an integer (or you write your own class). See [Matlab/Octave addition, losing digits of precision](http://stackoverflow.com/questions/13886821/matlab-octave-addition-losing-digits-of-precision/13887079) – carandraug Jul 11 '14 at 12:09
-
3
you could use the C style printf format.
sprintf("%.2f", 32.073)

Mingjiang Shi
- 7,415
- 2
- 26
- 31
-
Not a great solution for matrices though. You would need a nested loop: https://stackoverflow.com/a/11386211/1271772 – Nike May 25 '23 at 04:48