Float

Path: /src/type/float.coffee compiled to /lib/type/float.js

This will check a floating point number against a precise definition in which range it may be.

Sanitize options allowed:

  • sanitize - Boolean remove invalid characters
  • unit - String unit to convert to if no number is given
  • round - Boolean|String rounding of float can be set to true for arithmetic rounding or use floor or ceil for the corresponding methods
  • decimals - Integer number of decimal digits to round to

Check options:

  • min - Numeric the smallest allowed number
  • max - Numeric the biggest allowed number

Format options:

  • toUnit - String unit to convert value to
  • format - String format number as string
  • ‘locale’ - String locale format to use for string output

The result will be a Number or String representation of a number depending on the above parameters.

Additional Possibilities

Use theOr type to allow multiple ranges.

Alternative Number Checks

You may also use: -Integer -Percent -Byte

Schema Specification

Float is a float schema definition.

An object with the following keys allowed: sanitize, unit, round, decimals, min, max, toUnit, format, locale, title, description, key, type, optional, default. The following entries have a specific format:

sanitize

Sanitize is a flag which allows removing of non numeric characters before evaluating.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

unit

Source Unit is the unit in which an only numeric value is given, will transform to base unit.

A text entry which is optional. All control characters will be removed. It has to be at least 1 characters long.

round

Rounding is the value can be rounded in different ways.

It has to be one of the following types (optional):

  • Arithmetic Rounding is a flag which allows arithmetic rounding (till 4 down, from 5 up) if set to true.

    A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false.

  • Alternative Rounding is the alternative rounding method to be used.

    A text entry in which all control characters will be removed. Only the values: ‘floor’, ‘ceil’ are allowed.

decimals

Decimals are the number of decimal digits to round to.

An integer value which is optional. The value should be greater than 0.

min

Min Value is the minimal value to be set.

A numeric floating point number which is optional.

max

Max Value is the maximal value to be set.

A numeric floating point number which is optional. The value should be greater than <<>>.

toUnit

Result Unit is the unit to which to transform the value.

A text entry which is optional. All control characters will be removed.

format

Format is the numerical output format to use.

A text entry which is optional. All control characters will be removed.

locale

Locale is the language to be used for locale specific number format.

A text entry which is optional. All control characters will be removed. The text should match: /[1](?:-[A-Z]{2})?$/.

title

Title is the title used to describe the element.

A text entry which is optional. All control characters will be removed.

description

Description is the free description of the element.

A text entry which is optional. All control characters will be removed.

key

Binding to Keyname is the mapping to which key names in an object this element belongs.

A valid regular expression which is optional. It has to be one of the following types:

  • An object which has to be an instance of class RegExp.
  • A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
type

Type is the type of element.

A text entry in which all control characters will be removed.

optional

Optional is a flag defining if this element is optional.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

default

Default Value is the default value to use if nothing given.

A numeric floating point number which is optional.


  1. a-z ↩︎