PHP 8.5.0 Alpha 1 available for testing

Voting

: three plus zero?
(Example: nine)

The Note You're Voting On

PapaPinguoin
13 years ago
To view the very large and very small numbers (eg from a database DECIMAL), without displaying scientific notation, or leading zeros.

FR : Pour afficher les très grand et très petits nombres (ex. depuis une base de données DECIMAL), sans afficher la notation scientifique, ni les zéros non significatifs.

<?php
function floattostr( $val )
{
preg_match( "#^([\+\-]|)([0-9]*)(\.([0-9]*?)|)(0*)$#", trim($val), $o );
return
$o[1].sprintf('%d',$o[2]).($o[3]!='.'?$o[3]:'');
}
?>

<?php
echo floattostr("0000000000000001");
echo
floattostr("1.00000000000000");
echo
floattostr("0.00000000001000");
echo
floattostr("0000.00010000000");
echo
floattostr("000000010000000000.00000000000010000000000");
echo
floattostr("-0000000000000.1");
echo
floattostr("-00000001.100000");

// result
// 1
// 1
// 0.00000000001
// 0.0001
// 10000000000.0000000000001
// -0.1
// -1.1

?>

<< Back to user notes page

To Top