English, asked by ac056519, 20 days ago

separates the integral and fractional part.​

Answers

Answered by dev534332
0

Answer:

How to separate for example 12.345 into its integral part and fractional part? like integral part is 12 and fractional part is 0.345 in C++?

Anyways,

It's really simple.

Just go with your own given example.

double n = 12.345;

12.345

/ \

/ \

12. 0.345

As you can see for integer part you have to skip part after decimal point.

For this you can typecast your `double` or `float` to `int`

Typecast it and store in a variable.

int integer_part=(int)n;

Next the fractional part can be obtained by dividing integer part from fractional number.

12.345 - 12 =0.345;

For this

double fractional_part = n - integer_part;

Similar questions