Function print #
将值插入字符串模板。
Syntax #
math.print(template, values)
math.print(template, values, precision)
math.print(template, values, options)
Parameters #
| Parameter | Type | Description |
|---|---|---|
template |
string | 包含变量占位符的字符串。 |
values |
Object | Array | Matrix | 包含将填充到模板中的变量的对象或数组。 |
options |
number | Object | 格式化选项,或用于格式化数字的位数。有关所有选项的描述,请参阅 math.format 函数。 |
Returns #
| Type | Description |
|---|---|
| string | 插值字符串 |
Throws #
Type | Description —- | ———–
Examples #
// 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: '2013-03-23'
})
// the following outputs: 'My favorite fruits are apples and bananas !'
math.print('My favorite fruits are $0 and $1 !', [
'apples',
'bananas'
])