1 |
|
2 |
|
3 | # Function print
|
4 |
|
5 | Interpolate values into a string template.
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.print(template, values)
|
12 | math.print(template, values, precision)
|
13 | math.print(template, values, options)
|
14 | ```
|
15 |
|
16 | ### Parameters
|
17 |
|
18 | Parameter | Type | Description
|
19 | --------- | ---- | -----------
|
20 | `template` | string | A string containing variable placeholders.
|
21 | `values` | Object | Array | Matrix | An object or array containing variables which will be filled in in the template.
|
22 | `options` | number | Object | Formatting options, or the number of digits to format numbers. See function math.format for a description of all options.
|
23 |
|
24 | ### Returns
|
25 |
|
26 | Type | Description
|
27 | ---- | -----------
|
28 | string | Interpolated string
|
29 |
|
30 |
|
31 | ## Examples
|
32 |
|
33 | ```js
|
34 | // the following outputs: 'Lucy is 5 years old'
|
35 | math.print('Lucy is $age years old', {age: 5})
|
36 |
|
37 | // the following outputs: 'The value of pi is 3.141592654'
|
38 | math.print('The value of pi is $pi', {pi: math.pi}, 10)
|
39 |
|
40 | // the following outputs: 'hello Mary! The date is 2013-03-23'
|
41 | math.print('Hello $user.name! The date is $date', {
|
42 | user: {
|
43 | name: 'Mary',
|
44 | },
|
45 | date: new Date(2013, 2, 23).toISOString().substring(0, 10)
|
46 | })
|
47 |
|
48 | // the following outputs: 'My favorite fruits are apples and bananas !'
|
49 | math.print('My favorite fruits are $0 and $1 !', [
|
50 | 'apples',
|
51 | 'bananas'
|
52 | ])
|
53 | ```
|
54 |
|
55 |
|
56 | ## See also
|
57 |
|
58 | [format](format.md)
|