Numeric Values in YAML to ENV Conversion

Learn how YAML numeric types including integers, floats, octal, hexadecimal, and special values like infinity are handled when converting to ENV string format.

Basic Conversion

Detailed Explanation

YAML supports a rich set of numeric formats that all become plain strings in ENV files. Understanding these conversions is essential to avoid data loss or misinterpretation.

YAML numeric types:

# Standard integers and floats
port: 8080
timeout: 30.5
negative: -1
zero: 0

# Octal (common for file permissions)
file_mode_v1: 0755       # YAML 1.1 octal = decimal 493
file_mode_v2: 0o755      # YAML 1.2 octal = decimal 493

# Hexadecimal
max_memory: 0xFF         # decimal 255

# Scientific notation
threshold: 1.5e-3        # 0.0015

# Special values
max_connections: .inf    # infinity
undefined_ratio: .nan    # not a number

Converted to ENV:

PORT=8080
TIMEOUT=30.5
NEGATIVE=-1
ZERO=0
FILE_MODE_V1=493
FILE_MODE_V2=493
MAX_MEMORY=255
THRESHOLD=0.0015
MAX_CONNECTIONS=Infinity
UNDEFINED_RATIO=NaN

Critical conversion issues:

  1. Octal number expansion. YAML interprets 0755 as octal and converts it to decimal 493. If you intended the literal string "0755" (for example, a file permission argument for chmod), you must quote it in YAML: file_mode: "0755". In the ENV output, this becomes FILE_MODE=0755.

  2. Hexadecimal conversion. 0xFF becomes 255. The hex representation is lost. If you need the hex string, quote it: "0xFF".

  3. Infinity and NaN. These YAML special values have no standard ENV representation. They typically become the strings Infinity and NaN, which must be parsed explicitly by the consuming application.

  4. Scientific notation. 1.5e-3 may be expanded to 0.0015 or kept as 1.5e-3 depending on the converter. Both are valid number representations.

  5. Leading zeros. A value like 007 in YAML 1.1 is octal (decimal 7), not the string "007". In YAML 1.2, 007 remains the integer 7 (not octal). Always quote if you need the literal form.

Best practice: When the string representation matters more than the numeric value (file permissions, zero-padded IDs, hex colors), always quote the value in YAML before conversion to ENV.

Use Case

Converting a YAML configuration containing file permissions (0755, 0644), memory limits in hex notation, and scientific notation thresholds to ENV format for a containerized application startup script.

Try It — YAML ↔ ENV Converter

Open full tool