Taking 2 points input

Hey there!
I want to take input of only 2 decimal points. It means, if I give 2.54578, it'll just take 2 54. How can I do it?
Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>


int main()
{
    double d { 2.54578 };
    int above_0 { static_cast<int>(d) };
    int first_2_dec { static_cast<int>(d * 100) % 100 };
    std::cout << "Original value: " << d
              << "; part > 0: " << above_0
              << "; first two decimals: " << first_2_dec
              << '\n';
}


Output:
Original value: 2.54578; part > 0: 2; first two decimals: 54

What's static cast and how it works?
Topic archived. No new replies allowed.