Main Content


Class: mlreportgen.dom.Number
Package: mlreportgen.dom

Convert number to formatted text


formattedNumber = toString(numberObj)


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 an mlreportgen.dom.NumberFormat object in the Style property of the mlreportgen.dom.Number object specified by numberObj

  2. The specification in a NumberFormat object in the Style property of an 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.


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 = 

Version History

Introduced in R2021a