PHP 8.5.0 Alpha 1 available for testing

Voting

: min(nine, one)?
(Example: nine)

The Note You're Voting On

timo dot frenay at gmail dot com
14 years ago
Here is how to print a floating point number with 16 significant digits regardless of magnitude:

<?php
$result
= sprintf(sprintf('%%.%dF', max(15 - floor(log10($value)), 0)), $value);
?>

This works more reliably than doing something like sprintf('%.15F', $value) as the latter may cut off significant digits for very small numbers, or prints bogus digits (meaning extra digits beyond what can reliably be represented in a floating point number) for very large numbers.

<< Back to user notes page

To Top