Converts a string to a number either with or without decimals, depending on the format of the string.
Syntax
to_number(string|number $data, string $culture)
If $data is already a number, the number is returned.
If $data is not a string or number, then null
is returned.
Parameters
$data: Data is the string or number to convert.
$culture: Culture must be a language culture name based on ISO-639-1 (ie. ‘en-US‘, ‘es-ES‘).
Example
{
"String_a": "12",
"String_b": "12.3",
"String_c": "12,3",
"String_d": null,
"String_e": [0]
}
{
//English culture
"Number1": to_number(String_a, 'en-US'),
"Number2": to_number(String_b, 'en-US'),
"Number3": to_number(String_c, 'en-US'),
"Number4": to_number(String_d, 'en-US'),
"Number5": to_number(String_e, 'en-US'),
//Danish culture
"Number6": to_number(String_a, 'da-DK'),
"Number7": to_number(String_b, 'da-DK'),
"Number8": to_number(String_c, 'da-DK'),
"Number9": to_number(String_d, 'da-DK'),
"Number10": to_number(String_e, 'da-DK')
}
{
"Number1": 12,
"Number2": 12.3,
"Number3": 123,
"Number4": null,
"Number5": null,
"Number6": 12,
"Number7": 123,
"Number8": 12.3,
"Number9": null,
"Number10": null
}