Q:

How to separate whole number and decimal number to two different variable

I am  trying to separate whole number and decimal number 
two int variable 
#include <iostream>
#include <iomanip>
#include<math.h>

using namespace std;
int main()
{
    double initialAmount = 42800.13;
    double fractionalPart = initialAmount - floor(initialAmount);
    cout<<int(initialAmount)<<"\n"<<fractionalPart<<"\n";

}

Present output is 
42800
0.13

expected output
42800
13

It can be more than two decimal places .
any easy way to do that

A:

Maybe not the best solution, but at least it is simple :)
Store your double initialAmount in a int - which will truncate the decimal part. Then you have the number before the decimal point. Then subtract that from the initial value and you'll be left with just the part after the decimal point. Multiply that by however many powers of 10 that you deem significant and then again store that in a int and you'll have your two values.

A:

As suggested in the comments, it could help to convert the number into a string.  Here's one possibility:
#include <sstream>
#include <iostream>
#include <vector>
#include <string>

int main() {
  double d = 42800.13;
  std::vector<std::string> numbers_s;
  std::string s; 
  std::istringstream numberAsString(std::to_string( d ));
  while (getline(numberAsString, s, '.')) {
    numbers_s.push_back(s);
  }
  std::cout << "whole number:" << numbers_s[0] << std::endl;
  //[ remove trailing zeros from fractional part:
  numbers_s[1].erase(numbers_s[1].find_last_not_of('0') + 1, std::string::npos);
  //]
   std::cout << "fractional part:" << std::stoi(numbers_s[1]) << std::endl;
}

Error checks should be added to capture cases when the number does not contain a decimal point.

