DEV Community

Cover image for Setprecision | Floating types | C++
Imron
Imron

Posted on

Setprecision | Floating types | C++

🔹 setprecisionC++ da kasr aniqligini boshqarish

setprecision son nechta raqam bilan chiqarilishini belgilaydi.
U <iomanip> kutubxonasida joylashgan.

#include <iostream>
#include <iomanip>
using namespace std;

Enter fullscreen mode Exit fullscreen mode

1️⃣ Kangay ishlashi

double x = 3.1415926535;

cout << setprecision(4) << x;

Enter fullscreen mode Exit fullscreen mode

Natija

3.142
Enter fullscreen mode Exit fullscreen mode

Ushbu funksiya kasr sonlarni nuqtadan keyin x ta raqam aniqlikda yaxlitlaydi.

2️⃣ Faqat kasrdan keyingi sonlarni belgilash

Buning uchun fixed ishlatiladi:

cout << fixed << setprecision(4) << x;
Enter fullscreen mode Exit fullscreen mode

Natija

3.1416
Enter fullscreen mode Exit fullscreen mode

Endi bu kasrdan keyin 4 ta raqam degani.

Top comments (0)