In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article "how Mini Program converts strings into numbers" is not quite understood by most people except programmers. Today, in order to make you better understand "how Mini Program converts strings into numbers", the editor summarizes the following contents for you. It has a certain reference value, the detailed steps of the content are clear, and the details are handled properly. I hope you can get something through this article. Next let's take a look at the specific content.
1. Convert a string into a number:
C language library function: atoi implements this function.
Int atoi (const char * nptr)
Function description: parameter nptr string, returns zero if the first non-space character exists or is not a number or a plus or minus sign, otherwise it starts type conversion, and then stops conversion when a non-numeric (including Terminator\ 0) character is detected and returns an integer number.
The code is as follows:
# include # include # include / * function: string to int* Note: * 1, whether the string is empty; * 2, ignore\ t or space; * 3, overflow judgment; * 4, when the input string has only a "+" or "-" sign * 5. Scan the parameter src string, skip the previous space characters, do not start the conversion until you encounter a number or positive or negative symbol, and then end the conversion when you encounter a non-numeric or string end ('\ 0'), and return the result. * / int convertionStringToInt (char * src) {bool flag=false;long num=0; / * use long type, data overflow case * / int minus=0;if ((NULL = = src) | | ('\ 0strings = * src)) / / determine whether the string pointer is empty {return 0;} if (('\ t'= = * src) | | (''= = * src)) / ignore tab characters and space characters {src + + } if ('-'= = * src) / / determine whether the symbol {flag=true;src++;} else if ('+'= = * src) {src++;} minus=flag?-1:1;while ('\ 0'! = * src) {if (('0' = * src)) {num= num*10+minus* ((* src) -'0') If ((! flag & & num > 0x7FFFFFFF) | | (flag & & num < (signed int) 0x80000000)) / / determine whether the converted integer is overflowing. Note that both positive and negative numbers should judge {num = 0 num;} src++;} else {break; / / ends conversion}} return num when a non-numeric character is encountered } int main () {char data [8] [15] = {"4673", "15234234234", "- 3489", "+ 9776", "ab67", "123bd", "+", "-"}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 226
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.