SigServer:SignatureMath: Difference between revisions

From AniDB
Jump to navigation Jump to search
Line 99: Line 99:
  padding("2.40", 6, "left"); // Returns "2.40  "
  padding("2.40", 6, "left"); // Returns "2.40  "
  padding("1220.40", 6);      // Returns "1220.40"
  padding("1220.40", 6);      // Returns "1220.40"
==== date ====
''string'' '''date'''(''string'' format[, ''string'' time]);
Returns date and time according to the first argument. The format syntax is the same as PHP's date(). The optional argument may be a timestamp or string with date.
'''Example'''
date("Y-m-d");                        // Returns current date e.g. "2007-11-20"
date("H:i:s");                        // Returns current time, e.g. "19:50:37"
date("Y-m-d", "1995-10-03T20:30:37"); // Returns date "1995-10-03"
==== precision ====
''string'' '''precision'''(''number'' value, ''number'' precision);
Returns string containing value with a fixed number of decimals.
'''Example'''
precision(5, 2);    // Returns "5.00"
precision(5.25, 1); // Returns "5.2"
precision(5.26, 1); // Returns "5.3"
precision(5.24, 1); // Returns "5.2"

Revision as of 18:21, 2 December 2007

Function Reference

Mathematical

abs

number abs(number value);

Returns the absolute value of a number

Example

abs(1);  // Returns 1
abs(-1); // Returns 1

ceil

number ceil(number value);

Returns the ceiling of a number.

Example

ceil(1.4); // Returns 2
ceil(1.9); // Returns 2

floor

number floor(number value);

Returns the floor of a number.

Example

floor(1.1); // Returns 1
floor(1.9); // Returns 1

max

number max(number value1, number value2[, number ...]);

Returns the numerically highest value of the given arguments. At least two arguments are required.

Example

max(3, 5);           // Returns 5
max(3, 1.2, 5, 5.1); // Returns 5.1


min

number min(number value1, number value2[, number ...]);

Returns the numerically lowest value of the given arguments. At least two arguments are required.

Example

min(3, 5);           // Returns 3
min(3, 1.2, 5, 5.1); // Returns 1.2

mod

number mod(number dividend, number divisor);

Returns the reminder when dividing dividend with divider.

Example

mod(10, 3); // Returns 1

pow

number pow(number base, number exp);

Returns base to the power of exp.

Example

pow(3, 2); // Returns 9
pow(2, 3); // Returns 8

round

number round(number value[, number precision]);

Returns base to the power of exp.

Example

round(2.4);     // Returns 2
round(2.5);     // Returns 3
round(2.55, 1); // Returns 2.6

sqrt

number sqrt(number value);

Returns the square root of value.

Example

sqrt(9); // Returns 3

Miscellaneous

if

Alias of notempty();

notempty

mixed notempty(mixed value[, string true[, string false]]);

Check's if the first argument is not empty. Returns TRUE or FALSE if the optional arguments aren't specified. If they are specified it returns the second argument if TRUE and the third argument if FALSE.

Example

notempty("");                      // Returns false
notempty("Foobar");                // Returns true
notempty(6 > 2);                   // Returns true
notempty("", "Not empty", "Empty") // Returns "Empty"

padding

string padding(mixed value, number padding[, string align]);

Takes value and adds padding on left side if third argument isn't specified. Third argument is optional and may be "left" or "right" and specifies the padding alignment. Second argument specifies the padding width.

Example

padding("2.40", 6);         // Returns "  2.40"
padding("12.40", 6);        // Returns " 12.40"
padding("2.40", 6, "left"); // Returns "2.40  "
padding("1220.40", 6);      // Returns "1220.40"

date

string date(string format[, string time]);

Returns date and time according to the first argument. The format syntax is the same as PHP's date(). The optional argument may be a timestamp or string with date.

Example

date("Y-m-d");                        // Returns current date e.g. "2007-11-20"
date("H:i:s");                        // Returns current time, e.g. "19:50:37"
date("Y-m-d", "1995-10-03T20:30:37"); // Returns date "1995-10-03"

precision

string precision(number value, number precision);

Returns string containing value with a fixed number of decimals.

Example

precision(5, 2);    // Returns "5.00"
precision(5.25, 1); // Returns "5.2"
precision(5.26, 1); // Returns "5.3"
precision(5.24, 1); // Returns "5.2"