Skip to content

Commit

Permalink
Merge branch 'main' into s_improve_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
savalet authored Oct 27, 2024
2 parents 2a7713b + 23bad95 commit 6803f12
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/handler/put_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,59 @@
** display an int in hexadecimal format
*/

#include <stdio.h>

#include "my.h"

void printf_put_float(flags_t *flags)
{
return;
x += baby_put_nbr(entier);
baby_putchar('.');
x++;
for (int i = 0; i < precision; i++)
if (decimal[i] != 0)
x += baby_put_nbr(decimal[i]);
}

int printf_put_float_sav(flags_t *flags)
{
int x = 0;
float nb = va_arg(flags->args, double);
int entier = (int)nb;
int precision = flags->precision;
int decimal[precision];
int b = 10;
int tt;

for (int i = 0; i < precision; i++) {
tt = (int)(nb * b);
decimal[i] = tt % 10;
b = b * 10;
}
if (nb < 0) {
baby_putchar('-');
nb = nb * -1;
entier = nb;
}
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 6803f12

Please sign in to comment.