UNPKG

1.46 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function print
4
5Interpolate values into a string template.
6
7
8## Syntax
9
10```js
11math.print(template, values)
12math.print(template, values, precision)
13math.print(template, values, options)
14```
15
16### Parameters
17
18Parameter | Type | Description
19--------- | ---- | -----------
20`template` | string | A string containing variable placeholders.
21`values` | Object &#124; Array &#124; Matrix | An object or array containing variables which will be filled in in the template.
22`options` | number &#124; 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
26Type | Description
27---- | -----------
28string | Interpolated string
29
30
31## Examples
32
33```js
34// the following outputs: 'Lucy is 5 years old'
35math.print('Lucy is $age years old', {age: 5})
36
37// the following outputs: 'The value of pi is 3.141592654'
38math.print('The value of pi is $pi', {pi: math.pi}, 10)
39
40// the following outputs: 'hello Mary! The date is 2013-03-23'
41math.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 !'
49math.print('My favorite fruits are $0 and $1 !', [
50 'apples',
51 'bananas'
52])
53```
54
55
56## See also
57
58[format](format.md)