Calculation field: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Line 472: Line 472:
=== Functions and methods of Memento JavaScript ===
=== Functions and methods of Memento JavaScript ===


{{Functions and methods of Memento JavaScript}}
Functions are available to assist in crafting expressions to calculate a final result. Function calls may be typed into the expression, or the user may use the '''+Function''' button to display a tabbed list of functions that may be used.
; Note: The rest of this section documents the available functions. However, while the functions may be better explained here, it may be incomplete or even incorrect. The menus of available functions within Memento when using the '''+Function''' button are quite useful and will always be more recently updated than what is documented here.
 
=== Math functions ===
Unless otherwise specified, all numbers are ''real'' numbers.
 
{| class="wikitable" style="font-size:100%"
! Function !! Arguments !! Returns
|-
| '''abs''' || ''number''
| Absolute value of ''number''
|-
| '''acos''' || ''radians''
| Arc cosine of the angle
|-
| '''asin''' || ''radians''
| Arc sine of the angle
|-
| '''atan''' || ''radians''
| Arc tangent of the angle
|-
| '''atan2''' || ''x, y''
| Arc tangent of an angle, given its rectangular coordinates
|-
| '''ceil''' || ''number''
| Ceiling value of ''number''
|-
| '''cos''' || ''radians''
| Cosine of the angle
|-
| '''exp''' || ''integer''
| Exponential number ''e'' raised to the power of ''integer''
|-
| '''floor''' || ''number''
| Floor value of ''number''
|-
| '''log''' || ''number''
| Natural logarithm (base ''e'') of ''number''
|-
| '''max''' || ''number1, number2''
| The maximum value of ''number1'' & ''number2''
|-
| '''min''' || ''number1, number2''
| The minimum value of ''number1'' and ''number2''
|-
| '''pow''' || ''number, integer''
| ''number'' raised to the power of ''integer''
|-
| '''rint''' || ''real''
| ''real'' adjusted to the closest integer, returned as a ''real''
|-
| '''round''' || ''real''
| Closest ''integer'' to ''real''
|-
| '''sin''' || ''radians''
| Sine of the angle
|-
| '''sqrt''' || ''number''
| Square root of ''number''
|-
| '''tan''' || ''radians''
| Tangent of the angle
|-
| '''toDegrees''' || ''radians''
| Angle in degrees
|-
| '''toRadians''' || ''degrees''
| Angle in radians
|}
 
=== Date/Time Functions ===
 
{| class="wikitable" style="font-size:120%"
! Function !! Arguments !! Returns
|-
| '''datediff''' || ''date1, date2''
| Number of days between the 2 dates (''date2'' - ''date1'')
|-
| '''dateadd'''<br/>4 arguments || ''date,<br/>intervalDays,<br/>intervalMonths,<br/>intervalYears''
| ''date'' incremented by the date interval
|-
| '''dateadd'''<br/>7 arguments || ''date,<br/>intervalSeconds,<br/>intervalMinutes,<br/>intervalHours,<br/>intervalDays,<br/>intervalMonths,<br/>intervalYears''
| ''date'' incremented by the time interval
|-
| '''formatDate''' || ''seconds''
| Equivalent date string (seconds since start of Jan 1 1970)
|-
| '''formatDateTime''' || ''seconds''
| Equivalent date/time string (seconds since start of Jan 1 1970)
|-
| '''formatTime''' || ''seconds''
| Equivalent time string (seconds since start of Jan 1 1970)
|-
| '''now''' ||
| The current time in seconds since the start of Jan 1 1970<br/>Uses Universal Time (UTC) regardless of local settings or time zone
|-
| '''relativeTimeStr''' || ''startTime''
| String describing the elapsed time since the given start time
|-
| '''formatDuration''' || ''seconds''
| Duration as a string formatted as MM:SS or H:MM:SS
|}
 
=== String functions ===
Regarding string functions, an '''''index''''' is the relative number of a character within the string. The first string character has index 0 (zero).
 
{| class="wikitable" style="font-size:120%"
! Function !! Arguments !! Returns
|-
| '''numToStr''' || ''number''
| String representation of ''number''
|-
| '''compareTo''' || ''string1,<br/>string2''
| Zero, if the strings are equal<br/> A negative number, if ''string1'' < ''string2''<br/> A positive number, if ''string1'' > ''string2''
|-
| '''compareToIgnoreCase''' || ''string1,<br/>string2''
| Zero, if the strings are equal (ignoring case)<br/> A negative number, if ''string1'' < ''string2'' (ignoring case)<br/> A positive number, if ''string1'' > ''string2'' (ignoring case)
|-
| '''concat''' || ''string1,<br/>string2''
| String of ''string2'' appended to the end of ''string1''
<source lang="JavaScript">
concat(#{name}, ', Jr.')
</source>
|-
| '''endsWith''' || ''string1,<br/>string2''
| TRUE (1.0), if ''string1'' ends with ''string2''<br/> FALSE (0.0), if it doesn't
|-
| '''equals''' || ''string1,<br/>string2''
| TRUE (1.0), if the strings are identical<br/> FALSE (0.0), if not
|-
| '''equalsIgnoreCase''' || ''string1,<br/>string2''
| TRUE (1.0), if the strings are identical (ignoring case)<br/> FALSE (0.0), if not
|-
| '''indexOf''' || ''string1,<br/>string2,<br/>index''
| Within ''string1'' from ''index'' to the end, the index of the next occurrence of ''string2''<br/>-1, if no more occurrences
<source lang="JavaScript">
next = indexOf(#{Description}, ' and ', next)
</source>
|-
| '''length''' ||'' string''
| Length of (number of characters in) ''string''
|-
| '''replace''' || ''string,<br/>char1,<br/>char2''
| String of ''string'' with all matching ''char1''s replaced with ''char2''s
<source lang="JavaScript">
replace(#{Description}, ';', '.')
</source>
|-
| '''startsWith''' || ''string1,<br/>string2,<br/>index''
| TRUE (1.0), if ''string1'', starting at position ''index'', starts with ''string2''<br/> FALSE (0.0), if it doesn't
|-
| '''substring''' || ''string,<br/>startIndex,<br/>endIndex''
| The substring of ''string'' that starts at ''startIndex'' and ends at ''endIndex''
|-
| '''toLowerCase''' || ''string''
| The string ''string'' with all uppercase characters converted to lowercase
|-
| '''toUpperCase''' || ''string''
| The string ''string'' with all lowercase characters converted to uppercase
|-
| '''trim''' || ''string''
| The string ''string'' with all "white space" (blanks, tabs, etc) removed from both ends
|}
 
=== Logical functions ===
{| class="wikitable" style="font-size:120%"
! Function !! Arguments !! Returns
|-
| '''if''' || ''expression,<br/>valueIfTrue,<br/>valueIfFalse'' || One value if a logical expression is TRUE (not equal to 0.0)<br/>and another if it is FALSE (equal to 0.0)<br/>Read it as "If ''expression'' is true, then ''valueIfTrue'', else ''valueIfFalse''"
<source lang="JavaScript">
if(#{remaining} == 0, 'Done', 'Incomplete')
</source>
|-
| '''switch''' || ''expression,<br/>valueResultPairs,<br/>defaultResult'' || 1+(2*#pairs)+1 arguments<br/>The final result based on matching ''expression'' against the paired '''values''' to identify the paired '''result''' (or else ''defaultResult'') to be used
<source lang="JavaScript">
switch(#{count},
  1, 'One',
  2, 'Two',
  'Many')
</source>
|}

Navigation menu