My user enters values as floating point numbers(dollars and cents) and I am trying to perform accurate calculations with their input. To do this, the goal is to multiply their input by 100 and convert it to an integer. However, when I try to use cin to get their input as a double, it is not stored accurately ie. if they enter 15.03, the value is stored as 15.0299999999(based on debugging the code). While this is not a problem for my test cases, I foresee corner cases where rounding errors cause strange issues. Given that I am simply performing 2 decimal point calculations, is there a way around this? My code is below:
double ammount_spent;
cin >> ammount_spent;
int cents_spent=100*ammountspent;
cout cents_spent;