0

when i try to print double a=2343.34200000 it gives me only 2343.342 ??why this is happening can anybody tell me here

26th Apr 2021, 3:02 PM
Davinder Kumar
Davinder Kumar - avatar
4 odpowiedzi
0
irl maths, there's no need to write zeroes after a decimal, so the program ignores it. or it could be that double data-type could only store 8bytes, beyond that it can't
26th Apr 2021, 3:13 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
But there is a demand to print 2343.34200000 so what should i do 😟
26th Apr 2021, 3:15 PM
Davinder Kumar
Davinder Kumar - avatar
0
Davinder Kumar Use %.8f double t = 2343.34200000; printf ("%.8f\n", t); https://code.sololearn.com/c7Vzgaqi0PNM/?ref=app
26th Apr 2021, 4:17 PM
A͢J
A͢J - avatar
0
Use I/O manipulator from <iomanip> header #include <iostream> #include <iomanip> // std::fixed, std::setprecision int main() { double dbl_var {2343.34200000}; std::cout << std::fixed << std::setprecision( 8 ) << dbl_var << "\n"; // Reference: // https://en.cppreference.com/w/cpp/io/manip/fixed // https://en.cppreference.com/w/cpp/io/manip/setprecision return 0; }
26th Apr 2021, 7:13 PM
Ipang