mlreportgen.ppt.getDefaultNumberFormat
Description
returns the default number format specification as a character vector. To set the default
number format specification, use formatSpec
= mlreportgen.ppt.getDefaultNumberFormatmlreportgen.ppt.setDefaultNumberFormat
.
Examples
Format Numbers in Presentation
Add formatted numbers to a presentation by using the mlreportgen.ppt.Number
and mlreportgen.ppt.NumberFormat
classes. Set the number formatting for the first content slide using a default value for your session and for the second content slide to a format style for that specific Number
object.
Import the PPT namespace so that you do not have to use fully qualified names for the PPT API classes.
import mlreportgen.ppt.*
Set the default number formatting for the session.
setDefaultNumberFormat("%0.6f");
Create a presentation and add a title slide.
ppt = Presentation('myPresentation.pptx'); open(ppt); slideTitle = add(ppt,"Title Slide"); replace(slideTitle,"Title","Formatted Numbers");
Create the first title and content slide. Create an mlreportgen.ppt.Paragraph
object to use for the title of the slide.
slide1 = add(ppt,"Title and Content");
p1Title = Paragraph;
Create a Number
object with pi
and convert it to a string with the toString
method.
number1Obj = Number(pi); formattedNumber1 = toString(number1Obj);
Append the formatted number to the paragraph.
append(p1Title,string(char(960)) + " in default format: " ... + formattedNumber1); % char(960) - Unicode for the pi character
Replace the title in the first title and content slide with the paragraph.
replace(slide1,"Title",p1Title);
Display the default format in the content text box.
numberFormat = getDefaultNumberFormat(); p1Content = Paragraph("Number format is : "); p1Content.append(numberFormat); replace(slide1,"Content",p1Content);
Create the second title and content slide. Create an mlreportgen.ppt.Paragraph
object to use for the title of the slide.
slide2 = add(ppt,"Title and Content");
p2 = Paragraph;
Create a Number
object with pi
and convert it to a string with the toString
method. Limit the decimal places of pi
on this slide to two decimal points by specifying the format of the Number
and overriding the default number formatting.
number2Obj = Number(pi);
number2Obj.Style = NumberFormat("%0.2f");
formattedNumber2 = toString(number2Obj);
Append the formatted number to the paragraph.
append(p2,string(char(960)) + " in individual format: " ... + formattedNumber2); % char(960) - Unicode for the pi character
Replace the title in the second title and content slide with the paragraph.
replace(slide2,"Title",p2);
Display the individual format in the content text box.
p2Content = Paragraph("Number format is : "); p2Content.append("%0.2f"); replace(slide2,"Content",p2Content);
Close and view the presentation.
close(ppt); rptview(ppt);
Output Arguments
formatSpec
— Format specification
character vector
Format specification, returned as a character vector. The specification is a valid
format specification for the sprintf
function and uses one of these operators:
%f
%e
%E
%g
%G
If the format specification is an empty character vector, the PPT API formats
numbers using the maximum number of digits needed to represent the number accurately.
For more information about how the PPT API chooses a format specification, see mlreportgen.ppt.Number
.
Version History
Introduced in R2024b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)