From 23bad95c4d5fd049486184c6c6dd17c08524a422 Mon Sep 17 00:00:00 2001 From: Marc Agen Date: Sun, 27 Oct 2024 19:36:39 +0100 Subject: [PATCH] fix the put_float --- src/handler/put_float.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/handler/put_float.c b/src/handler/put_float.c index 260f8f9..5616970 100644 --- a/src/handler/put_float.c +++ b/src/handler/put_float.c @@ -4,7 +4,7 @@ ** File description: ** display an int in hexadecimal format */ - +#include #include "my.h" static @@ -23,7 +23,7 @@ void printf_put_float2( x += baby_put_nbr(decimal[i]); } -int printf_put_float(flags_t *flags) +int printf_put_float_sav(flags_t *flags) { int x = 0; float nb = va_arg(flags->args, double); @@ -46,3 +46,22 @@ int printf_put_float(flags_t *flags) printf_put_float2(decimal, x, precision, entier); return (0); } + +int printf_put_float(flags_t *flags) +{ + double nbr = va_arg(flags->args, double); + int copy = (int)nbr; + int precision = flags->precision; + + if (precision == -1) + precision = 6; + if (nbr < 0) + baby_putchar('-'); + baby_put_nbr(copy); + baby_putchar('.'); + nbr -= copy; + for (int i = 0; i < precision; i++) + nbr*= 10; + baby_put_nbr(nbr); + return baby_intlen(copy, 10) + baby_intlen(nbr, 10) + 1; +}