A bug related to the Number_format function?

Source: Internet
Author: User

Recently doing an online project that mimics Excel functionality. One of the features, the data in the data list, is aggregated to the last column. It would have been no difficulty. Once the data is fetched directly from the database, the foreach is added to the line. It was so simple that it took less than five minutes to write the function and didn't bring the brain to the body at all.

Two days after a casual browsing page, found that the results of the statistics are incorrect. So wrestling, unexpectedly did not find my calculations have any logical bug. But there is no bug, the final calculation is not correct, it must be where there is a problem, but I do not find it now.

After repeated output of the original data, unexpectedly found that the data taken from the database is Number_format processed results, the thousand points added a comma, has become a string. In addition, I also used the coercion type conversion (int) to make the numeric string into the int type, which is convenient to add.

Understand the problem, it is good to take a method to fix the bug. Since it's a comma, let's just remove the comma. The Str_replace function is used to replace the comma with an empty string. This turns the natural data into a string number and then casts the city int type.

The results of the final statistics are calculated, and the data is a long string. Very inconvenient to read. So also to the final statistical results to use Number_format to again thousand bits plus commas, so that the statistical data is best for users to understand.

Entered the company is about three months, also see the code that Daniel wrote. Combine your personality and habits to talk about understanding.

First of all, programmers are not yards, the work of the day, not with a lot of meaningless characters in dealing with, the work of the program more like a writer, write a story with words.

The code is neat or not, to the most, I think in all the elements, the code is neat, is the most important.

A neat code, not from the understanding of the point of view. Comfortable typesetting, the right to stay white, clear comments, will make follow-up code people feel that this is a hard writing code, impetuous mood will slowly calm down.

If even the basic variable equals sign is not aligned, it can only be bad. The next time you look at your own code, you also feel nauseous.

The naming of variables must be standardized. You can have your own variable naming conventions, and if you have your own development specifications in your team development, be sure to follow them.

The name of the variable should be named as much as possible in English, I use the name of the small hump, that is, the first word lowercase, the second word capitalized.

Ken can I do the design of the reason, any one thing, first to look good, and then to talk about how to use.

After all, the code you go to see him every day, really do not have the heart of their own world are indecisive disorderly code.

May the code be like a poem, a life like a rainbow.

A bug related to the Number_format function?

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.