Floating-Point Types
Cangjie provides three floating-point types: Float16, Float32, and Float64, corresponding to IEEE 754 half-precision, single-precision, and double-precision floating-point numbers. Float64 is the default floating-point type—floating-point literals are inferred as Float64.
Floating-point literals can be expressed in decimal or hexadecimal. Decimal floating-point numbers must include a decimal point or exponent part (e or E, base 10). Hexadecimal floating-point numbers start with 0x, with exponent using p or P (base 2). Types can be explicitly specified using suffixes f16, f32, f64.
The code on the right demonstrates floating-point operations and different representations. 2.5e10 means 2.5 × 10¹⁰, and 0x1.5p2 means 1.3125 × 2² = 5.25. Try modifying the values of price or quantity to calculate different totals.
Float64 has approximately 15 significant digits of precision, while Float32 has about 6. For scenarios requiring high precision, prefer using Float64.