Function o = real2eng(r)
o = real2eng(r,p)
o = real2eng(r,p,outputarray)
o = real2eng(r,p,outputarray,harmonise)
[o,c] = real2eng(...)
returns a string representation in engineering
notation of real r. The representation has the
following features:
-- the real is displayed as a m-th power-of-ten,
where m has one of the values:
... +9, +3, 0, -3, -6 ...
-- by preference, a smaller power-of-ten is
displayed. E.g. a real 1.23e7 is displayed
as 12.3e6, and not as 0.0123e9;
-- by preference, when all values are between
9999 and 0.0009, they are displayed as such;
-- the format of the output string is explaned
in the help text of m-file real2str.m;
-- at default for a matrix of reals r, it is
tried to harmonise, i.e. to display each real
with the same power-of-ten as much as
possible. This feature is handy for a series
of values which make up the ticks on an axis
of a plot.
The optional input argument p is the precision,
a scalar. If the argument is missing or empty,
the precision is 8. The precision is the number
of digits at which the real is rounded off for
the determination of the number of significant
digits in the real. Note that the first
significant digit is counted; e.g. 1.2 as well
as 0.12 have a number of 2 digits!
The possible maximal precision depends on the
internal data type. See e.g.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
-- Float32Array:
1.2*10^-38 to 3.4*10^38
4 bytes
32-bit IEEE floating point number
7 significant digits e.g., 1.234567
-- Float64Array:
5.0*10^-324 to 1.8*10^308
8 bytes
64-bit IEEE floating point number
16 significant digits e.g., 1.23456789012345
If input argument r is a matrix with more than
one element, the output argument o contains a
single string, otherwise the ouput is a cell
array of strings. The output will always be a
cell array, if the optional input argument
outputarray is 1. If the argument is missing
or empty, the default value is 0.
The feature of harmonisation is switched off
by setting the optional inputargument harmonise
to 0. If the argument is missing or empty, the
default value is 1.
Optional output argument c is a struct combining
the input, intermediate results and output.
Internally, the function calls the following
non-standard m-files:
real2mtspot.m
real2str.m
(c) 2026 fabien van mook
2026.08.20 release of this file within package "fvm-real2eng" under GNU GPLv3+