Percent
Path:
/src/type/percent.coffee
compiled to/lib/type/percent.js
Number validation like float but specified for percent and other fraction numbers like per mille…
Sanitize options allowed:
sanitize
-Boolean
remove invalid charactersunit
-String
unit to convert to if no number is givenround
-Boolean|String
rounding of float can be set to true for arithmetic rounding or usefloor
orceil
for the corresponding methodsdecimals
-Integer
number of decimal digits to round to
Check options:
min
-Numeric
the smallest allowed numbermax
-Numeric
the biggest allowed number
Format options:
toUnit
-String
unit to convert value toformat
-String
format number as string- ‘locale’ -
String
locale format to use for string output
Possible Units
- ‘%’ - percent value - 10-2 = 1 part in 100
- ‘‰’ - per mille value - 10-3 = 1 part in 1000
- ‘‱’, ‘bp’ - basis point - 10-4 = 1 part in 10000
- ‘pcm’ - per cent mille - 10-5 = 1 part in 100000
- ‘ppm’ - parts per million - 10-6
- ‘ppb’ - parts per billion - 10-9
- ‘ppt’ - parts per trillion - 10-12
- ‘ppq’ - parts per quadrillion - 10-15
Schema Specification
Percent is a percent 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 value.
A text entry which is optional. All control characters will be removed. Only the values: ‘%’, ‘‰’, ‘‱’, ‘bp’, ‘pcm’, ‘ppm’, ‘ppb’, ‘ppt’, ‘ppq’ are allowed.
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. Only the values: ‘%’, ‘‰’, ‘‱’, ‘bp’, ‘pcm’, ‘ppm’, ‘ppb’, ‘ppt’, ‘ppq’ are allowed.
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]$/.
- An object which has to be an instance of class
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.
a-z ↩︎