Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Standard.php

function Standard::pScalar_Float

File

vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php, line 229

Class

Standard

Namespace

PhpParser\PrettyPrinter

Code

protected function pScalar_Float(Scalar\Float_ $node) : string {
    if (!is_finite($node->value)) {
        if ($node->value === \INF) {
            return '1.0E+1000';
        }
        if ($node->value === -\INF) {
            return '-1.0E+1000';
        }
        else {
            return '\\NAN';
        }
    }
    // Try to find a short full-precision representation
    $stringValue = sprintf('%.16G', $node->value);
    if ($node->value !== (double) $stringValue) {
        $stringValue = sprintf('%.17G', $node->value);
    }
    // %G is locale dependent and there exists no locale-independent alternative. We don't want
    // mess with switching locales here, so let's assume that a comma is the only non-standard
    // decimal separator we may encounter...
    $stringValue = str_replace(',', '.', $stringValue);
    // ensure that number is really printed as float
    return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal