Prototype: int(string)

Return type: int

Description: Convert numeric string to int.

Arguments:

  • string: string, in the range: .*

If string represents a floating point number then the decimals are truncated.

Example:

bundle agent main
{
  vars:
      "data" data => '{"acft_name": "A320neo",
                       "engine_num": "2",
                       "price_in_USD": "123.456789k"}';

      "engines" int => int("$(data[engine_num])");
      "ballpark_price" int => int("$(data[price_in_USD])");

  reports:
      "A320neo has $(engines) engines and costs about $(ballpark_price) USD.";
}
R: A320neo has 2 engines and costs about 123456 USD.

This policy can be found in /var/cfengine/share/doc/examples/int.cf and downloaded directly from github.

See Also: string()

History:

  • Introduced in 3.18.0