%% Format Numbers into Strings
% Format pi to eight decimal places and return it as a string.

A = pi

%
% Starting in R2017a, you can create strings using double quotes. Specify formatSpec as a string.

formatSpec = "%.8f"

%

str = compose(formatSpec,A)

%
% Create a numeric array that contains values of pi and e. Use the %e and %f operators with different precisions.

A = [pi exp(1)]

%

formatSpec = "The value of pi is %.2e; the value of e is %.5f.";
str = compose(formatSpec,A)

% Copyright 2012 The MathWorks, Inc.