simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

print.md (1514B)


      1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
      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 &#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 
     26 Type | Description
     27 ---- | -----------
     28 string | Interpolated string
     29 
     30 
     31 ### Throws
     32 
     33 Type | Description
     34 ---- | -----------
     35 
     36 
     37 ## Examples
     38 
     39 ```js
     40 // the following outputs: 'Lucy is 5 years old'
     41 math.print('Lucy is $age years old', {age: 5})
     42 
     43 // the following outputs: 'The value of pi is 3.141592654'
     44 math.print('The value of pi is $pi', {pi: math.pi}, 10)
     45 
     46 // the following outputs: 'hello Mary! The date is 2013-03-23'
     47 math.print('Hello $user.name! The date is $date', {
     48   user: {
     49     name: 'Mary',
     50   },
     51   date: new Date(2013, 2, 23).toISOString().substring(0, 10)
     52 })
     53 
     54 // the following outputs: 'My favorite fruits are apples and bananas !'
     55 math.print('My favorite fruits are $0 and $1 !', [
     56   'apples',
     57   'bananas'
     58 ])
     59 ```
     60 
     61 
     62 ## See also
     63 
     64 [format](format.md)