I have the code to convert a number to binary but can't figure out how to make it work for a fixed point decimal number. For example, how could I convert a number such as 5.25
?
Here is the code I have right now:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> intVector;
int number, digit ;
int base ;
cout << "Enter a base: ";
cin >> base;
cout << "Enter a number: ";
cin >> number;
while(number > 0)
{
digit = number % base ;
intVector.push_back(digit) ;
number = number / base ;
}
while(!intVector.empty())
{
cout<<intVector.back() ;
intVector.pop_back();
}
return 0;
}
Any pointers how to convert a fixed decimal number? I need it to print up to 20 decimal places.