C Language Development Kit/Functions/DfToA

From OptiWiki

Jump to: navigation, search
Description Converts a double (float) into a readable string.
char * dftoa(char * buffer, double a);
char * buffer
Character buffer into which the result string is copied. The maximum number of characters that will be stored in the buffer is 12.
double a
64-bit floating point value that is to be converted into a string.
Returns Character pointer to the result string of the converted value
Remarks This functions convert a floating point variable in a same way as the %g type format specifier of printf would.

This means it will either be converted to the form [-]dddd.dddd, where dddd is one or more decimal digits or to the scientific notation with an 'e', depending on which of the two is more compact.

Make sure the result string is atleast 12 characters in size.

#include <stdio.h>
#include <math.h>
#include <time.h>
#include "lib.h"
void main(void)
    double a;
    float b,c,d, e;
    char buffer[15];
    a = 2.5;
    b = 2.0;
    c = a*b;
    d= 0.5f;
    printf("\fFloat test\n");
    a = (double)c*sin(d*3.1f);
    e = (float)a/d;

Personal tools