castNum<T extends num> function

T castNum<T extends num>(
  1. num value
)

Converts a num to the instrument's numeric type T.

Observable callbacks and batch callbacks report num values, while the instrument's storage is typed; an int instrument truncates a double.

Implementation

T castNum<T extends num>(num value) {
  if (T == int) return value.toInt() as T;
  if (T == double) return value.toDouble() as T;
  return value as T;
}