What is the function of this use of floating-point arithmetic in PHP?

Source: Internet
Author: User
Tags unpack
What is the function of this use of floating-point arithmetic in PHP?

Please take a look at the example of floating point arithmetic in Baidu Encyclopedia first

Http://wenku.baidu.com/view/9ba120a108a1284ac85043d8.html?re=view

The hexadecimal 42c88000.
Use the IEEE754 standard 32-bit floating-point number format to calculate the result equals 100.25

To figure out the hexadecimal c1c90000 is 25.125.

Are there any existing functions?

Write an example for me, thank you very much.


Thank you


Reply to discussion (solution)

  



equals 100.25

$s = ' 42c88000 '; Echo current (Unpack (' F ', pack (' V ', Hexdec ($s))));
100.25
$s = ' c1c90000 '; Echo current (Unpack (' F ', pack (' V ', Hexdec ($s))));
-25.125

can also

$s = ' c1c90000 '; Echo current (Unpack (' F ', pack (' h* ', join (', Array_reverse (Str_split ($s, 2)))));
-25.125

#1 code is valid only for positive numbers
$a = ' c1c90000 '; echo hextodecfloat ($a);
-6.875
needs to be perfected

Thank you moderator for your help.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.