Separating double into integer and decimal parts

前端 未结 11 1058
日久生厌
日久生厌 2020-12-06 10:20

I am trying to separate a double into the integer and decimal parts

So for example, the number 24.4 should be separated into 24 and 4.

int integer =          


        
11条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 10:40

    ![Here is my Solution][1]

    here is my solution. I used a simple method in C Programming to split the Fractional Numbers in two Different Integers...Here below is the Code

    #include
    void main()
    {
    float x=24.56; int y=(int)x; float z=(x-y)*1000000000; int zd=(int)z;
    printf("%lf",x);
    printf("\ninteger Part %d\n",y);
    printf("\nDecimal Part %d\n",zd);
    }
    

    Output


    24.559999 integer Part 24

    Decimal Part 559999488

提交回复
热议问题