String to floating-point integer to floating-point number

Source: Internet
Author: User

sprintf more useful

Float 2 Char

You can use sprintf (): For example, float,double to char#include<stdio.h> #include <stdlib.h> void Main () {float f= 1234.5; Double d= 789.8765;char sf[20],sd[20];sprintf (SF, "%f", f);  float to charsprintf (SD, "%LF", D); Double to char printf ("%s%s\n", SF,SD);  To come out to see}

Char 2 float

You can use the library function atof.

1 Function name Atof

2 statement

Double atof (const char *nptr);

3 Header Files

#include <stdlib.h>

4 Features

Converts the string in the parameter nptr to floating-point data and returns.

5 It is important to note that a valid string, that is, a string stored in real or scientific notation, can be converted or the conversion will go wrong. For example, a string such as "SJDHK" cannot be converted to a floating-point number. In the case of a "1.23sdf" form, it will only be processed to the last number, and the result is 1.23.

5 Sample Code

String to floating-point integer to floating-point number

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.