libft/src/ft_dtoa.c

39 lines
1.2 KiB
C
Raw Normal View History

2023-04-15 06:46:13 +02:00
/* ************************************************************************** */
/* */
/* :::::::: */
2023-10-26 18:06:04 +02:00
/* ft_dtoa.c :+: :+: */
2023-04-15 06:46:13 +02:00
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2021/02/02 03:46:17 by djonker #+# #+# */
2023-10-26 18:06:04 +02:00
/* Updated: 2023/10/18 16:56:16 by houtworm ######## odam.nl */
2023-04-15 06:46:13 +02:00
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_dtoa(long double n)
{
char p[100];
long double temp;
long long i;
char *t;
char *f;
i = n;
temp = (long double)n - (long double)i;
i = 0;
while (temp * 10 < 1 && i < 49)
{
temp = temp * 10;
p[i] = '0';
i++;
}
p[i] = '\0';
i = ft_lftoi(n);
t = ft_ltoa(i);
f = ft_strjoin(p, t);
free(t);
return (f);
}