pushswap/libft/src/ft_dtoa.c
2023-03-01 04:36:58 +01:00

39 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_dtoa.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2021/02/02 03:46:17 by djonker #+# #+# */
/* Updated: 2023/02/07 00:38:46 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#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);
}