数据类型转换函数strtod | atoi | atol

手把手教你用MOS管设计双电源自动切换电路(附零压降方案) 本文详细介绍了使用MOS管设计双电源自动切换电路的完整方案,包括基础电路拓扑、零压降优化设计及实战调试技巧。针对外接电源与电池供电的无缝切换需求,提供低损耗MOS管选型建议和性能实测数据,帮助工程师解决传统二极管方案的压降与漏电问题。 阅读详情

strtod  > Convert string to double

atoi   > Convert string to int

atol > Convert string to long int

 

 

1、strtod

double strtod ( const char * str, char ** endptr );

Convert string to double

Parses the C string str interpreting its content as a floating point number and returns its value as a double . If endptr is not a null pointer, the function also sets the value pointed by endptr to point to the first character after the number.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. A pointer to the rest of the string after the last valid character is stored in the object pointed by endptr .

A valid floating point number for strtod is formed by a succession of:

  • An optional plus or minus sign
  • A sequence of digits, optionally containing a decimal-point character
  • An optional exponent part, which itself consists on an 'e' or 'E' character followed by an optional sign and a sequence of digits.

If the first sequence of non-whitespace characters in str does not form a valid floating-point number as just defined, or if no such sequence exists because either str is empty or contains only whitespace characters, no conversion is performed.

Parameters

str
C string beginning with the representation of a floating-point number.
endptr
Reference to an already allocated object of type char* , whose value is set by the function to the next character in str after the numerical value.
This parameter can also be a null pointer, in which case it is not used.

 

Return Value

On success, the function returns the converted floating point number as a double value.
If no valid conversion could be performed, a zero value (0.0 ) is returned.
If the correct value is out of the range of representable values, a positive or negative HUGE_VAL is returned, and the global variable errno is set to ERANGE .
If the correct value would cause underflow, zero is returned and errno is set to ERANGE .

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* strtod example */

#include <stdio.h>

#include <stdlib.h>


int
 main ()
{
  char
 szOrbits[] = "365.24 29.53"
;
  char
 * pEnd;
  double
 d1, d2;
  d1 = strtod (szOrbits,&pEnd);
  d2 = strtod (pEnd,NULL);
  printf ("The moon completes %.2lf orbits per Earth year./n"
, d1/d2);
  return
 0;
}



Output:


The moon completes 12.37 orbits per Earth year.

2、atoi
int atoi ( const char * str );

Convert string to integer

Parses the C string str interpreting its content as an integral number, which is returned as an int value.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

Parameters

str
C string beginning with the representation of an integral number.

 

Return Value

On success, the function returns the converted integral number as an int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* atoi example */

#include <stdio.h>

#include <stdlib.h>


int
 main ()
{
  int
 i;
  char
 szInput [256];
  printf ("Enter a number: "
);
  fgets ( szInput, 256, stdin );
  i = atoi (szInput);
  printf ("The value entered is %d. The double is %d./n"
,i,i*2);
  return
 0;
}



Output:

Enter a number: 73 The value entered is 73. The double is 146.

3、atol


long int atol ( const char * str );

Convert string to long integer

Parses the C string str interpreting its content as an integral number, which is returned as a long int value.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

Parameters

str
C string containing the representation of an integral number.

 

Return Value

On success, the function returns the converted integral number as a long int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, LONG_MAX or LONG_MIN is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* atol example */

#include <stdio.h>

#include <stdlib.h>


int
 main ()
{
  long
 int
 li;
  char
 szInput [256];
  printf ("Enter a long number: "
);
  gets ( szInput );
  li = atol (szInput);
  printf ("The value entered is %d. The double is %d./n"
,li,li*2);
  return
 0;
}



Output:


Enter a number: 567283
The value entered is 567283. The double is 1134566.

 


        
【YOLO目标检测全栈实战】98 YOLO模型在低光照环境下的自适应增强策略 你有没有遇到过这种情况?深夜加班调试产线检测模型,车间灯光昏暗,摄像头采集的图片黑乎乎一片,YOLO模型直接“罢工”——漏检率飙升到40%以上。上个月我在一个汽车零部件质检项目里就栽了跟头:白天模型跑得飞起,mAP@0.5达到0.92,可一到夜班,同样的产线、同样的零件,mAP直接掉到0.63。客户拍着桌子问我:“你这模型怎么还分白天黑夜?” 阅读详情

相关推荐

51单片机AHT20-21源代码

传感器输出经过 标定的数字信号,标准 I 2 C 格式。AHT20 配有一个全新设计的 ASIC专用芯片、一 个经过改进的MEMS半导体电容式湿度传感元件和一个标准的片上温度传感元件,其 性能已经大大提升甚至超出了前一代传感器的可靠性水平,新一代温湿度传感器, 经过改进使其在恶劣环境下的性能更稳定。但是现在网上的大多数原码都是针对stm32等的这种多位单片机,而我们都知道51单片机是8位单片机,无法对浮点数进行运算,对32位的整数计算有时候也不是很准确,所以我对网上stm32的例程进行了修改。...

wd0710的博客 4549

GPT-4技术解析:从Transformer架构到三阶段训练与实战应用

自然语言处理领域的核心突破源于Transformer架构及其自注意力机制,该机制通过并行计算实现了对长序列数据的高效建模。基于此构建的大规模语言模型,通过海量数据预训练掌握了语言的统计规律与知识表示。在工程实践中,结合监督微调与基于人类反馈的强化学习等技术,模型得以与人类价值观对齐并遵循复杂指令。这类技术已广泛应用于智能对话、代码生成与多模态内容创作等场景。以GPT-4为代表的先进模型,正是通过极致化模型规模、训练范式与架构创新,将语言模型的上下文理解、逻辑推理及多模态处理能力推向新高度,成为当前人工智能工

weixin_30608503的博客 719

具身智能端到端大模型VLA (Vision Language Action)

在语言为条件的机器人任务中,策略必须具备理解语言指令、视觉感知环境并生成适当动作的能力,这就需要VLA的。例如,在自动驾驶领域,传统的做法是将感知、预测、规划等步骤分开处理,而VLA则试图用一个统一的框架来替代这种分立的方法。另外,VLA的模型对于算力的需求很大,单片AI算力1000Tops的Thor大概率会延期发布,加上英伟达芯片的量产时间与成本挑战,以及在国内的应用情况,对车企而言是个大问题。以谷歌DeepMind推出的RT-2为例,该模型可以在新的物体、背景和环境中表现出显著改善的性能。

具身智能机器人 1万+

类型转换函数(特此记录)

一、atoi函数(将字符串转换成整型数) 相关函数 atof,atol,atrtod,strtol,strtoul 表头文件 #include 定义函数 int atoi(const char *nptr); 函数说明 atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。 返回值 返回转换后

张亮校的专栏 1023

SAP物料主数据表结构全解析:ABAP开发与MM模块必知必会

本文深入解析SAP物料主数据的核心表结构,涵盖MARA、MAKT、MARC、MARD及MVKE等关键表。详细阐述了物料主数据在ABAP开发和MM模块中的存储逻辑与关联关系,帮助开发者和顾问高效处理数据查询、增强功能及业务故障排查,是掌握SAP物料管理基础的必读指南。

weixin_29216957的博客 379

15 君正IPC库开发总结

在前面的章节中,我们介绍了君正ISP、视频采集、音频采集、音频播放、云台电机、移动侦测算法、人形侦测算法、移动跟踪算法等的封装。那么,应用层如何使用这些封装好的接口呢?根据设计模式中的依赖倒置原则:高层次的模块不应该依赖于低层次的模块,它们都应该依赖于抽象。因此,应用层应当只能感知到我们封装的接口类,而不应当感知到其对应的具体实现类。

hope_wisdom的技术博客 1662

C++|atoi,atol,strtod,atof

函数说明 1.atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时(‘\0’)才结束转换,并将结果返回。 2.参数nptr字符串可包含正负号、小数点或E(e)来表示指数部分,如123.456或123e-2。返回转换后的浮点型数。atof()与使用strtod(nptr,(char**)NULL)结果相同。 执行结果 atoi(将字符串转换成整型数) 定义函数 函数说明 atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上

DX390609的博客 735

C# 上位机程序中的数据采集与存储技术:从采集到持久化的完整解决方案

本文系统讲解C#上位机程序如何实现设备数据采集与持久化。主要内容包括:1)多种数据采集方式(串口通信、Modbus、OPC等)及代码示例;2)详细对比不同存储技术(CSV、SQLite、关系型数据库等)的优缺点;3)提供SQLite等存储实现代码;4)推荐分层系统架构(采集-缓存-存储-可视化);5)性能优化建议(多线程采集、异步存储、批量写入等)。文章强调应根据项目需求选择合适的技术方案,构建高效稳定的数据采集存储闭环系统。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1025

atoi,atol,strtod,atof

atof(将字符串转换成浮点型数)相关函数atoi,atol,strtod,表头文件#include 定义函数double atof(const char *nptr);函数说明atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。参数nptr字符串可包含正负号、小数点或...

weixin_34032792的博客 218

解决宿主机Ping不通虚拟机的问题

在使用虚拟机的过程中,我们常常会遇到宿主机和虚拟机之间无法相互通信的问题。具体来说,我们要查看虚拟机和宿主机的 IP 地址,然后尝试进行 Ping 测试。在某些情况下,我们可能发现 Ping 虚拟机不通,接下来我将分享如何解决这个问题。

howard2005的专栏 7万+

【软考高级架构】案例题考前突击6——大数据架构

前一类的数据主要由流量方以接口的方式提供(比如对接的腾讯广点通平台),后一类则是某网特有的数据,通过买家的浏览、下单、付款日志算出来。1. 在数据层面只维护一张包含所有指标的MySQL表,表中的stday字段作为索引,stday=当天的保存实时数据,stday<当天的保存离线数据。典型的大数据架构,除了Lambda架构之外,还有kappa架构,这两个架构的区别如下标所示,请补充表中空(1)-(4)第二,实时数据只对接了内部的kafka消息,没有实时的获取第三方的曝光、点击、浏览数据。

qq837993702的博客 66

atoi,atol,strtod,strtol,strtoul实现类型转换

 一、atoi C语言库函数名: atoi    功 能: 把字符串转换成整型数.    名字来源:array to integer 的缩写.    原型: int atoi(const char *nptr);    函数说明: 参数nptr字符串,如果第一个非空格字符不存在或者不是数字也不是正负号则返回零,否则开始做类型转换,之后检测到非数字(包括结束符 \0) 字符时停止转换

lq87002128的专栏 722

ESP32设备驱动-TB6612FNG直流电机驱动

TB6612FNG 是一款出色的双电机驱动器,非常适合将两个小型直流电机(例如微型金属齿轮电机)连接到微控制器,它还可以用于控制单个双极步进电机。 基于 MOSFET 的 H 桥比 L298N 和 Sanyo 的 LB1836M 等旧式驱动器中使用的基于 BJT 的 H 桥效率高得多,后者允许将更多电流输送到电机,而从逻辑电源汲取的电流更少 (对于真正低电压的应用,LB1836 仍然具有 TB6612 的优势)。

视觉与物联智能 3403

atoi,atol,strtod,strtol,strtoul详解

 atof(将字符串转换成浮点型数)相关函数atoi,atol,strtod,strtol,strtoul表头文件#include “stdlib.h"定义函数double atof(const char *nptr);函数说明atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时(/0)才结束转换,并将结果返回。参数nptr

pureshf的专栏 1733

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

C语言的常用类型转换函数(atoi,atol,strtod,strtol,strtoul)

<br />atof(将字符串转换成浮点型数)<br />相关函数<br /> atoi,atol,strtod,strtol,strtoul<br />表头文件<br /> #include <stdlib.h><br />定义函数<br /> double atof(const char *nptr);<br />函数说明<br /> atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('')才结束转

qikaibinglan的专栏 2705

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

C语言字符串 数字转换函数大全

atof(将字符串转换成浮点型数)atoi(将字符串转换成整型数)atol(将字符串转换成长整型数)strtod(将字符串转换成浮点数)strtol(将字符串转换成长整型数)strtoul(将字符串转换成无符号长整型数)toascii(将整型数转换成合法的ASCII 码字符)toupper(将小写字母转换成大写字母)tolower(将大写字母转换成小写字母)     atof(将字符串转换成浮

李逸波(PMP) 1024

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

字符串转换函数

头文件:stdlib.h 1、函数名: atof 功 能: 把字符串转换成浮点数 名字来源:ascii to floating point numbers 的缩写 用 法: double atof(const char *nptr); 函数说明 atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字

>>--» 唯n1.情缘«--<< 409

atof,atol,atrtod,strtol,strtoul的使用

一、atoi函数(将字符串转换成整型数) 相关函数 atof,atol,atrtod,strtol,strtoul 表头文件 #include 定义函数 int atoi(const char *nptr); 函数说明 atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。 返回值

楚兴 1794

C++字符串转化为数字的库函数

C++字符串转化为数字的库函数 原文链接:http://blog.youkuaiyun.com/tsinfeng/article/details/5844838 1、atoi 功 能:把一字符串转换为整数 用 法:int atoi(const char *nptr);详细...

dichuangheng8094的博客 436

【转】C常用字符转换函数

1 atof(将字符串转换成浮点型数) 2 相关函数 3 atoi,atol,strtod,strtol,strtoul 4 表头文件 5 #include <stdlib.h> 6 定义函数 7 double atof(const char *nptr); 8 函数说明 9 atof()...

weixin_33705053的博客 82

c语言常用数据类型转换整理

你要发送原始数据流还是格式化输出? 如果是格式化按原子说的,用sprintf/printf; 如果发送原始内存数据流,可按下面发送, 发送 #define BYTE0(pointer) (*((char*)(&pointer)+0)); #define BYTE1(pointer) (*((char*)(&pointer)+1));...

weixin_30652897的博客 94

C++制服串转换篇

atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoulNNULinux联盟 表头文件

329

37、C语言常用库函数-转换类型类

转换常用函数(函数原型所在头文件为math.h、stdlib.h、ctype.h、float.h) char*ecvt(doublevalue,intndigit,int*decpt,int*sign) 将浮点数value转换成字符串并返回该字符串 char*fcvt(doublevalue,intndigit,int*decpt,int*sign) 将浮点数value...

hopegrace的博客 284

c语言中字符串转数字的函数

ANSI C 规范定义了 atof()、atoi()、atol()、strtod()、strtol()、strtoul()共6个可以将字符串转换为数字的函数,大家可以对比学习。另外在 C99 / C++11 规范中又新增了5个函数,分别是atoll()、strtof()、strtold()、strtoll()、strtoull() 具体的用法可以参考:http://www.cplusp...

liming0931的专栏 1004

c++类型转化

2008-10-24 10:37版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 <br />http://ivanvic.blogbus.com/logs/1920125.html <br /><br />atof(将字符串转换成浮点型数) <br />相关函数 <br />atoi,atol,strtod,strtol,strtoul <br />表头文件 <br />#include <br />定义函数 <br />double atof(const char *nptr); <br

轨迹 326

(2)Linux_C_数据转换函数

atof(将字符串转换成浮点型数)atoi(将字符串转换成整型数)atol(将字符串转换成长整型数)ecvt(将浮点型数转换成字符串,取四舍五入)fcvt(将浮点型数转换为字符串,取四舍五入)gcvt(将浮点型数转换为字符串,取四舍五入)strtod(将字符串转换成浮点型数)strtol(将字符串转换成长整型数)strtoul(将字符串转换成无符号长整型数)toascii(将...

weixin_34280237的博客 85
上一篇: atof 函数参考
下一篇: c++ point operation
Qicz
博客等级 码龄16年 56粉丝 122原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值