Main Content

toString

Class: mlreportgen.dom.Number
Namespace: mlreportgen.dom

Convert number to formatted text

Since R2021a

Syntax

formattedNumber = toString(numberObj)

Description

formattedNumber = toString(numberObj) converts the number specified by numberObj to formatted text.

The conversion uses the first of these format specifications that it finds:

  1. The specification in the mlreportgen.dom.NumberFormat object in the Style property of the object specified by numberObj

  2. The specification in the NumberFormat object in the Style property of the element, such as a paragraph, list, or table, that contains the specified Number object

  3. The default specification set by mlreportgen.dom.setDefaultNumberFormat

If the conversion does not find a format specification, the conversion uses the maximum number of digits needed to represent the number accurately.

You can use this method to see the formatted text that results from adding a mlreportgen.dom.Number object to a report.

Input Arguments

expand all

Number to convert, specified as an mlreportgen.dom.Number object.

Output Arguments

expand all

Formatted number, returned as a character vector.

Examples

expand all

In this example, toString uses the format specified by a NumberFormat object that is included in the Style property of the Number object.

import mlreportgen.dom.*
numberObj = Number(pi);
numberObj.Style = [numberObj.Style {NumberFormat("%0.2f")}];
formattedNumber = toString(numberObj)
formattedNumber = 
'3.14'

Version History

Introduced in R2021a