Skip to content

Commit

Permalink
fix the put_float
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAgen committed Oct 27, 2024
1 parent c98ae71 commit 23bad95
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/handler/put_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** File description:
** display an int in hexadecimal format
*/

#include <stdio.h>
#include "my.h"

static
Expand All @@ -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);
Expand All @@ -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;
}

0 comments on commit 23bad95

Please sign in to comment.