cub3d/libft/src/ft_round.c

40 lines
1.1 KiB
C
Raw Normal View History

2023-10-25 13:56:45 +02:00
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_round.c :+: :+: :+: */
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2021/02/02 07:26:00 by djonker #+# #+# */
/* Updated: 2023/02/07 00:40:48 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_round(int n, int h)
{
int ht;
ht = h;
if ((n % 10) > 5)
n = n + 1;
while (ht > 0)
{
if ((n % 10) > 5)
{
n = n / 10;
n = n + 1;
}
else
n = n / 10;
ht--;
}
while (h > 0)
{
n = n * 10;
h--;
}
return (n);
}