An error occurred while calculating garbled characters

Source: Internet
Author: User
One method left to solve the garbled problem. If there are four zeros, garbled characters may occur. For example, 0.01*0.00770000e-5 (garbled) should be equal to 0.00007. I don't know why php has such an error. Note: The original decimal point must be retained. Do not give away. How can this problem be solved? ------ Solution -------------------- 1. this is not garbled, it is scientific notation. 2. the round () function can specify the number of digits to the decimal point $ x.
If there are four zeros, garbled characters may occur.
For example, 0.01*0.007 = 7.0E-5 (garbled)
It should be 0.00007.

I don't know why php has such an error.

Note: The original decimal point must be retained. Do not give away. How can this problem be solved?

------ Solution --------------------
1. this is not garbled. it is a scientific notation.
2. the round () function can specify the digits of the decimal point.
$ X = 0.0000722;
$ S = round ($ x, 5 );
Echo $ s;
------ Solution --------------------
1. sprintf:
PHP code
  
------ Solution --------------------
PHP code
Echo bcmul (0.01, 0.007, 5); // 0.00007
------ Solution --------------------
Learned
------ Solution --------------------
Okay, it's disgusting.

$ S = 0.01*0.007;
Echo number_format ($ s, 5 ,'.','');
------ Solution --------------------
Discussion

$ S = number_format ($ x, 6 ,'.','');
The result is 0.000070.

How to remove the following 0 to 0.00007

------ Solution --------------------
Discussion
If there are four zeros, garbled characters may occur.
For example, 0.01*0.007 = 7.0E-5 (garbled)
It should be 0.00007.

I don't know why php has such an error.

Note: The original decimal point must be retained. Do not give away. How can this problem be solved?

------ Solution --------------------
Well. You can do this without adding 0:

PHP code
       

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.