File Number.lua

Functions

Number:fmtPrec (val, prec) Format number to string with specified precision.
Number:getAsNumber (a) Get a number from a variable whose type has not been pre-assured.
Number:getNumber (a, nameToThrow) Determine if a number, and if so, return it's value, otherwise return nil.
Number:isInteger (num) Determine if number is integer.
Number:isNonZero (value) Check if value is non-zero number.
Number:isNonZero (value) Check if value is non-zero number.
Number:isWithin (num1, num2, amt) Determine if number is within a certain amount of another number +/-
Number:new (t) Constructor for new instance.
Number:newClass (t) Constructor for extending class.
Number:numberFromString (s) Try to convert a string to a number, without croaking if the string is nil, null, or isn't a number...
Number:signedString (v) takes a number (or string representation of a number) and returns a string with sign prepended.


Functions

Number:fmtPrec (val, prec)
Format number to string with specified precision.

Parameters:

  • val:
  • prec:
Number:getAsNumber (a)
Get a number from a variable whose type has not been pre-assured.

Parameters:

  • a:

Usage:

  • This function was invented when I thought the above would fail when 's' not string (e.g. number), but that seems OK now, so this function is may be completely redundent.
  • If number, then returned verbatim, if string, then attempt to convert to number, otherwise returns nil.
  • The intended use is for cases when a number is required, but user or legacy code may have left something else where a number is expected, in which case, the old value is to be ignored...
  • never throws an error. 
Number:getNumber (a, nameToThrow)
Determine if a number, and if so, return it's value, otherwise return nil.

Parameters:

  • a:
  • nameToThrow:

Usage:

    never throws error. 
Number:isInteger (num)
Determine if number is integer.

Parameters:

  • num:
Number:isNonZero (value)
Check if value is non-zero number.

Parameters:

  • value:

Usage:

    value can be nil, but if non-nil - must be number. 
Number:isNonZero (value)
Check if value is non-zero number.

Parameters:

  • value:

Usage:

    value can be nil, but if non-nil - must be number. 
Number:isWithin (num1, num2, amt)
Determine if number is within a certain amount of another number +/-

Parameters:

  • num1:
  • num2:
  • amt:
Number:new (t)
Constructor for new instance.

Parameters:

  • t:
Number:newClass (t)
Constructor for extending class.

Parameters:

  • t:
Number:numberFromString (s)
Try to convert a string to a number, without croaking if the string is nil, null, or isn't a number...

Parameters:

  • s:
Number:signedString (v)
takes a number (or string representation of a number) and returns a string with sign prepended.

Parameters:

  • v:

Valid XHTML 1.0!