2018-06-16 15:39:07 +02:00

63 lines
1.8 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-print">Function print <a href="#function-print" title="Permalink">#</a></h1>
Interpolate values into a string template.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.print(template, values)
math.print(template, values, precision)
math.print(template, values, options)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`template` | string | A string containing variable placeholders.
`values` | Object &#124; Array &#124; Matrix | An object or array containing variables which will be filled in in the template.
`options` | number &#124; Object | Formatting options, or the number of digits to format numbers. See function math.format for a description of all options.
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
string | Interpolated string
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
// the following outputs: 'Lucy is 5 years old'
math.print('Lucy is $age years old', {age: 5})
// the following outputs: 'The value of pi is 3.141592654'
math.print('The value of pi is $pi', {pi: math.pi}, 10)
// the following outputs: 'hello Mary! The date is 2013-03-23'
math.print('Hello $user.name! The date is $date', {
user: {
name: 'Mary',
},
date: new Date(2013, 2, 23).toISOString().substring(0, 10)
})
// the following outputs: 'My favorite fruits are apples and bananas !'
math.print('My favorite fruits are $0 and $1 !', [
'apples',
'bananas'
])
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[format](format.html)