Search code examples
phpstringlong-integerstring-conversion

How can I convert long float to string in PHP?


I have very long float 0.000000000000000000000000000001

Aтв I need to get hash from STRING '0.000000000000000000000000000001'!

Because

hash('sha224', 0.000000000000000000000000000001); //2121895602ff05385d872035b131385bfb69d19bf4bf266abc3aaa9d

But

hash('sha224', '0.000000000000000000000000000001'); //f764c4d0e89a57e2e6c3fa04badb6d25c01a096a8c277126063bfb11

Example

$nm=0.000000000000000000000000000001;
$nm3=(string)$nm;
echo hash('sha224', $nm3); //2121895602ff05385d872035b131385bfb69d19bf4bf266abc3aaa9d

is not working. What can I do? Thanks.


Solution

  • this works

    <?php
    $nm=0.000000000000000000000000000001;
    
    
    echo hash('sha224',sprintf('%.30f',$nm)); 
    //f764c4d0e89a57e2e6c3fa04badb6d25c01a096a8c277126063bfb11
    
    ?>