The sex of the ID card by the WPS intelligent judgment

Source: Internet
Author: User

In the application of identifying the gender based on the ID number, most people are accustomed to using the nested if function to determine whether the ID number is 18 digits or 15 digits, and then extract the 17th or 15th digit, which is odd, when judged as "male" or even when judged as "female".

Such as:
=if (Len (A2) =18,if (mod (a2,17,1), 2, "male", "female"), IF (Len (A2) =15,if (mod (Right (a2,1), 2), "Male", "female"))

Although this can get the correct results, but due to two of the 18-digit and 15-digit ID card to judge and operation, resulting in the formula is too long, less efficient. In fact, we can avoid repeated judgments by adding simple computations to the IF function, see the following formula:
=if (MOD (A2, (LEN (A2) =18) *2+15,1), 2, "male", "female")

In this formula, if the A2 cell is 18 digits, the value of LEN (A2) =18 in the formula is 1, multiplied by 2, with a value of 2, followed by 15, equals 17, and if A2 is 15, then the value of LEN (A2) =18 is 0, multiplied by 2 plus 15, the value is 15, In this way, the mid function is used to intelligently take the 17th or 15-digit number 15th in the 18-digit number, and then as a mod parameter, correctly determine the gender of the ID holder. The same method can also be used to intelligently calculate the 18-bit and 15-bit ID card date of birth and other information, the specific way to spend your brains, extrapolate.

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.