zoukankan      html  css  js  c++  java
  • atof()函数详解

    atof()函数

    atof():double atof(const char *str );

    功 能: 把字符串转换成浮点数

    str:要转换的字符串。

    返回值:每个函数返回 double 值,此值由将输入字符作为数字解析而生成。 如果该输入无法转换为该类型的值,则返回值为 0.0。

    函数说明 :atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('')才结束转换,并将结果返回,str字符串可包含正负号、小数点或E(e)来表示指数部分。

     1  #include <stdio.h>
     2  #include <stdlib.h>
     3     int main(){
     4         char *a = "-100.23",
     5              *b = "200e-2",
     6              *c = "341",
     7              *d = "100.34cyuyan",
     8              *e = "cyuyan";
     9         printf("a = %.2f
    ", atof(a));
    10         printf("b = %.2f
    ", atof(b));
    11         printf("c = %.2f
    ", atof(c));
    12         printf("d = %.2f
    ", atof(d));
    13         printf("e = %.2f
    ", atof(e));
    14         system("pause");
    15         return 0;
    16   
    执行结果:
    a = -100.23
    b = 2.00
    c = 341.00
    d = 100.34
    e = 0.00
  • 相关阅读:
    杜教筛学习笔记
    AtCoder Beginner Contest 188 F
    求和公式
    洛谷P4848 崂山白花蛇草水 权值线段树+KDtree
    二次剩余学习笔记
    Miller Rabin素数检测与Pollard Rho算法
    半平面交学习笔记
    凸包习题总结
    多项式半家桶
    CF997解题报告
  • 原文地址:https://www.cnblogs.com/feifanrensheng/p/7894488.html
Copyright © 2011-2022 走看看