-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atof.c
32 lines (29 loc) · 1.25 KB
/
ft_atof.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atof.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edelangh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/07/15 17:47:29 by edelangh #+# #+# */
/* Updated: 2015/01/20 15:38:16 by edelangh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
double ft_atof(const char *str)
{
double result;
int i;
result = (double)ft_atoi(str);
i = ft_len_untill(str, '.');
if (i)
{
if (result >= 0 && str[0] != '-')
result += ((double)ft_atoi(str + i + 1))
/ ((ft_strlen(str + i + 1) * 10));
else
result -= ((double)ft_atoi(str + i + 1))
/ ((ft_strlen(str + i + 1) * 10));
}
return (result);
}