9

After a calculation I got 32.073 .I need it to round to 32.07 using Octave.Please can somebody help me?

AnoAPI
  • 124
  • 1
  • 1
  • 8

3 Answers3

7

You can do:

res = round(100 * 37.073) / 100
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
  • 1
    It gives 37.070. I need 37.07.Need to drop '3'. – AnoAPI Jul 11 '14 at 09:54
  • @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
  • Thank you for the proper directing – AnoAPI Jul 12 '14 at 13:32
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
1

You can just type format bank in the begining

Aggelos M
  • 71
  • 10