tostring() / toint() / todouble()
Every column and value in Kusto has a type: string, int, long (whole numbers), real (decimal
numbers), bool, datetime, timespan or dynamic. These functions convert between them:
| Function | Returns |
|---|---|
tostring(x) |
text |
toint(x) |
a 32-bit whole number (int) |
tolong(x) |
a 64-bit whole number (long) |
todouble(x), toreal(x) |
a decimal number (real) |
Common reasons to convert
- Decimal division.
count()returns whole numbers, and whole number divided by whole number is rounded down. Convert one side:todouble(Failed) / Total. - Values from dynamic columns. A property read from JSON, like
LocationDetails.city, has the typedynamic. Convert it before comparing, grouping or sorting:tostring(LocationDetails.city),todouble(...latitude). See parse_json and dynamic columns. - Building text.
strcat()and string comparisons want text:tostring(RemotePort).
toint() and tolong() of a decimal number drop the fraction (toward zero): toint(-7.9) is -7.
What this site doesn’t support yet
Converting text to a number (toint("42")) and converting decimal numbers or dates to text are
refused with a clear message on this site, because their exact behaviour differs between engines. A
conversion that fails in real Kusto returns null rather than an error.
Examples
SigninLogs
| summarize Total = count(), Failed = countif(ResultType != "0") by ClientAppUsed
| extend WholeNumber = Failed / Total, Share = todouble(Failed) / TotalDividing two whole numbers rounds down, so WholeNumber is 0 for almost every row.
SigninLogs
| extend Lat = todouble(LocationDetails.geoCoordinates.latitude)
| summarize North = max(Lat), South = min(Lat)DeviceNetworkEvents
| summarize Ports = make_set(tostring(RemotePort)) by Protocol
| extend Example = toint(7.9)toint() of a decimal drops the fraction: 7.9 becomes 7.
Practice it
None of the free exercises needs this one yet.
+ 6 in the full SC-200 set · all exercises