Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::cout << std::fixed << std::setprecision(std::numeric_limits<double>::digits10 + 1) << value << std::endl;
- #include <iostream>
- #include <iomanip>
- #include <limits>
- void print(double value)
- {
- const auto digits = std::numeric_limits<double>::digits10;
- std::cout << std::setfill(' ') << std::setw(digits + 4);
- std::cout << std::fixed << std::setprecision(digits) << value << std::endl;
- }
- int main()
- {
- double value = 9.12;
- print(value);
- }
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class IM {
- double d;
- size_t ww;
- char c;
- public:
- IM(double val, size_t whole_size, char imbue = ' ')
- : d(val), ww(whole_size), c(imbue) {}
- int get_whole() const
- {
- return d;
- }
- int get_fraction() const
- {
- stringstream s;
- s << d - get_whole();
- int k;
- s.ignore(2); // пропускаем '0' и '.'
- s >> k;
- return k;
- }
- friend ostream& operator <<(ostream& os, const IM& m)
- {
- os << setw(m.ww) << setiosflags(ios_base::left) <<setfill(m.c)
- << m.get_whole() << '.' << m.get_fraction();
- return os;
- }
- };
- double d = 2.45;
- IM dd(d, 10, '5');
- cout << dd << endl << dd.get_whole() << endl << dd.get_fraction();
- /* вывод:
- 2555555555.45
- 2
- 45
- */
Add Comment
Please, Sign In to add comment