Rust

number

Module

How PHP prints floats.

PHP formats floats with zend_gcvt: ndigit significant digits (mode 2), or the shortest round-trip digits when the precision setting is -1 (mode 0, exponent threshold 17), switching to exponent notation when the decimal point is more than ndigit places right or more than 3 places left of the digits. The mantissa always has a fraction (1.0E+25).

  • (string) $float, echo, string interpolation, string comparison use the precision setting (PRECISION, -1 as Appwrite's php.ini sets it): to_string.
  • json_encode, var_export use serialize_precision (-1) and a lowercase e: serialize.

Contents

use utopia_php_std::number::gcvt;
Rust
pub fn gcvt(value: f64, precision: i32, exp_char: char) -> String

zend_gcvt(value, precision, '.', exp_char), with PHP's special values. precision is the ini value: -1 selects the shortest round-trip digits.

use utopia_php_std::number::serialize;
Rust
pub fn serialize(f: f64) -> String

json_encode($float) / var_export with serialize_precision = -1.

use utopia_php_std::number::to_string;
Rust
pub fn to_string(f: f64) -> String

(string) $float at the precision setting (PRECISION).

Rust
pub const PRECISION: i32 = -1i32;

The precision ini Appwrite runs PHP with (docker/php.ini): -1, the shortest round-trip digits, so floats keep every digit when they become strings (PDO binds and fetches them as strings at this setting). PHP's own default is 14; gcvt prints at any other setting.