Casts

i32() and f64.

i32() and f64.

Goal

Cast f64 18.6 down to i32.

@external("env", "log")
declare function log(n: i32): void;

@external("env", "logStr")
declare function logStr(s: string): void;

export function main(): void {
  let price: f64 = 40.5;
  log(i32(price));
}
@external("env", "log")
declare function log(n: i32): void;

@external("env", "logStr")
declare function logStr(s: string): void;

export function main(): void {
  let units: i32 = 12;
  let asFloat: f64 = f64(units);
  log(i32(asFloat));
}
@external("env", "log")
declare function log(n: i32): void;

@external("env", "logStr")
declare function logStr(s: string): void;

export function main(): void {
  log(i32(8.9));
}
@external("env", "log")
declare function log(n: i32): void;

@external("env", "logStr")
declare function logStr(s: string): void;

export function main(): void {
  log(i32(f64(5) * 2.0));
}