How to split a number into integer and decimal parts in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int main(void) {

    double number = 3.14159;

    double integer, decimal;

    decimal = modf(number, &integer);

    printf("Integer = %lf\n", integer);
    printf("Decimal = %lf \n", decimal);

    return 0;
}



/*
run:

Integer = 3.000000
Decimal = 0.141590

*/

 



answered Jul 29, 2022 by avibootz

Related questions

1 answer 146 views
1 answer 148 views
3 answers 180 views
2 answers 124 views
...