Function File: y = truncate (x, order, method)
Function File: y = truncate (…, method)

Truncates X to order of magnitude.

The optional argument method can be a hanlde to a function used to truncate the number. Default is round.

Examples:

   format long
   x = 987654321.123456789;
   order = [3:-1:0 -(1:3)]';
   y = truncate (x,order)
y =
  987654000.000000
  987654300.000000
  987654320.000000
  987654321.000000
  987654321.100000
  987654321.120000
  987654321.123000

   format
   [truncate(0.127,-2), truncate(0.127,-2,@floor)]
ans =
   0.13000   0.12000

See also: round,fix,ceil,floor.

Package: miscellaneous