Wiki

effect · round_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Rounds a variable
Example: round_variable = num_dogs

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

round_variable is commonly used in scenarios where a variable needs to be converted to an integer after undergoing complex mathematical operations (multiplication, division, percentage calculations, etc.). For example, when calculating factory output shares, population quotas, or resource allocation ratios for a country, rounding the result to an integer prevents floating-point errors in subsequent comparisons or displays.

# Example: Calculate reward based on 30% of industrial capacity, round to integer, then use
set_variable = { var = reward_amount value = industrial_capacity_factor }
multiply_variable = { var = reward_amount value = 0.3 }
round_variable = reward_amount
# After this, reward_amount is guaranteed to be an integer and can be safely used in comparisons or assignments

Synergy

  • [multiply_variable](/wiki/effect/multiply_variable) — Multiplication operations very easily produce decimals; typically round_variable immediately follows to round the result.
  • [divide_variable](/wiki/effect/divide_variable) — Division almost inevitably produces floating-point numbers and is the most frequent operation requiring subsequent rounding.
  • [clamp_variable](/wiki/effect/clamp_variable) — After rounding, variables often need to be constrained within a reasonable range; using both together ensures numerical validity.
  • [check_variable](/wiki/trigger/check_variable) — Perform variable comparisons only after rounding to avoid conditions that can never be precisely met due to floating-point precision discrepancies.

Common Pitfalls

  1. Using the wrong command on temporary variables: round_variable only operates on persistent variables (variable). To round a temp_variable, you must use round_temp_variable instead. The script will not throw an error, but the operation will have no effect, making it extremely difficult to debug.
  2. Mistaking rounding for floor division: HOI4's round_variable performs standard rounding (banker's rounding) rather than direct truncation. If your logic requires strict floor division, use modulo_variable to subtract the remainder first; do not rely on round_variable as a substitute for floor operations.