Gcvt (convert the float number to a string and rounding it out)

Source: Internet
Author: User
Tags float number
/* Gcvt (convert the float number to a string and rounding it out) related functions: ECVT, fcvt, and sprintf header file # include <stdlib. h> define the function char * gcvt (double number, size_t ndigits, char * BUF). The function indicates that gcvt () is used to convert the parameter number into an ASCII string, the ndigits parameter indicates the number of digits displayed. Gcvt () differs from ECVT () and fcvt () in that the string converted by gcvt () contains the decimal point or positive or negative sign. If the conversion is successful, the converted string will be placed in the space specified by the Buf pointer. The Return Value Returns a string pointer, which is the Buf pointer. Additional instructions */# include <stdlib. h> main () {double A = 123.45; Double B =-1234.56; char * PTR = malloc (10); int decpt, sign; gcvt (A, 5, PTR ); printf ("A value = % s \ n", PTR); PTR = gcvt (B, 6, PTR); printf ("B value = % s \ n ", PTR);}/* execute a value = 123.45b value =-1234.56 */

 

Gcvt (convert the float number to a string and rounding it out)

Related Article

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.