reference:evaluator:as

The As operator performs two functions - conversion and formatting.

Conversion: varname As type

Converts the variable varname to the specified type. Valid types are:

boolboolean (true or false)
intsigned 32-bit integer
uintunsigned 32-bit integer
int64signed 64-bit integer
uint64unsigned 64-bit integer
doubledouble-precision floating point
datedate/time
strstring
pathpath

When converting from a string to a date, valid input formats are:

  • YYYY-MM-DD
  • YYYY-MM-DD HH:MM:SS
  • HH:MM:SS

Times must be in 24-hour format, minutes and seconds are optional. If a time is specified on its own, today's date is assumed.

Formatting: varname As format

Formats the variable varname using the specified formatting code.

Various formatting operations are available.

  • Date/time values can be formatted using the D#, T# and A# prefix codes
  • File size values using the codes shown below
  • Zero-padding to p places using #p or %0p
  • Right-justify to p places using %p
  • Left-justify to p places using %-p
  • Internal-justify:
    • For negative numbers to p places using %_p
    • For positive numbers %+p
  • Limit to p decimal places using %.p
  • Zero-pad to p decimal places with %.0p
  • Convert to hexadecimal using %x (lowercase) or %X (uppercase)

Where it makes sense the above codes can be combined, e.g. %_+8 would internal-justify a number to 8 places whether it was positive or negative.

File size format

Use value as size to automatically format a number as a file size using the default settings. You can also use the following keywords to control the units:

sizeAutomatic (bytes/KB/MB etc) with user-configured decimal/binary unit option
sztAutomatic with traditional units (1 KB = 1024 bytes)
sziAutomatic with binary units (1 KiB = 1024 bytes)
szdAutomatic with decimal units (1 KB = 1000 bytes)
bytesBytes
kbKilobytes, traditional units
mbMegabytes, traditional units
gbGigabytes, traditional units
tbTerabytes, traditional units
pbPetabytes, traditional units
kibKilobytes, binary units
mibMegabytes, binary units
gibGigabytes, binary units
tibTerabytes, binary units
pibPetabytes, binary units
kbdKilobytes, decimal units
mbdMegabytes, decimal units
gbdGigabytes, decimal units
tbdTerabytes, decimal units
pbdPetabytes, decimal units
  • You use %.x to specify the number of decimal places, e.g. %.3mib. or %.03kb to zero-pad
  • Use %^ to round up to the nearest kilobyte, e.g. %^kb.
  • Use %0 in front of the "automatic" keywords to force 0 bytes to be formatted as kilobytes


Example:

d = "2023-09-23" as date;
Output(d as "D#dd-MMM-yyyy");
--> 23-Sep-2023

i = 1 as double / 3;
Output(i as "%-.3");
--> 0.333

i = 183743933;
output(i as "%.3kb");
--> 179,437.435 KB

See also: Format