types.castNumber {tableschema.r} | R Documentation |
Cast numbers of any kind including decimals
Description
Cast numbers of any kind including decimals.
Usage
types.castNumber(
format,
value,
options = {
}
)
Arguments
format |
no options (other than the default) |
value |
number to cast |
options |
available options are "decimalChar", "groupChar" and "bareNumber", where
|
Details
The lexical formatting follows that of decimal in XMLSchema: a non-empty finite-length sequence of decimal digits separated by a period as a decimal indicator. An optional leading sign is allowed. If the sign is omitted, "+" is assumed. Leading and trailing zeroes are optional. If the fractional part is zero, the period and following zero(es) can be omitted. For example: '-1.23', '12678967.543233', '+100000.00', '210'.
The following special string values are permitted (case need not be respected):
NaN
: not a numberINF
: positive infinity-INF
: negative infinity
A number MAY also have a trailing:
exponent
: thisMUST
consist of an E followed by an optional + or - sign followed by one or more decimal digits (0-9)
See Also
Types and formats specifications
Examples
types.castNumber(format = "default", value = 1)
types.castNumber(format = "default", value = "1.0")
# cast number with percent sign
types.castNumber(format = "default", value = "10.5%", options = list(bareNumber = FALSE))
# cast number with comma group character
types.castNumber(format = "default", value = "1,000", options = list(groupChar = ','))
types.castNumber(format = "default", value = "10,000.50", options = list(groupChar = ','))
# cast number with "#" group character and "&" as decimal character
types.castNumber(format = "default", value = "10#000&50",
options = list(groupChar = '#', decimalChar = '&'))