DEV Community 👩‍💻👨‍💻

Cover image for Round() and fixed setprecision() functions
Jamol Meyliyev
Jamol Meyliyev

Posted on

Round() and fixed setprecision() functions

  • Raund() funksiyasi nima?

Elementar matematikada siz yaxlitlash degan tushunchani eshitgan bo'lsangiz kerak.Yaxlitlash yerik sonlar yoki sonning standard shaklidan uzoqroq bo'lgan shaklda berilgan sonlarni ixchamlab olish uchun ishlatiladi deyish mumkin.

Quyida round() funksiya ishlatilish sintaksisini ko'rib o'tamiz.

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

int main(){

float son;
cout<<"Sonni kiriting: ";
cin>>son;
cout<<"Natija: "<<round(son);

return 0;
  }

Console:

Sonni kiriting: 12.234234

Natija: 12



Enter fullscreen mode Exit fullscreen mode
  • fixed setprecision() functions funksiyasi nima?

Ushbu funksiya haqida qisqacha va elementar tushuntiradigan bo'lsam, Ushbu funksiya ham round() funksiyasi kabi yaxslitlash amalini bajaradi faqat ushbu funksiyani round() funksiyasidan farqi round() funksiyasi berilgan float yoki double tipidagi sonni integer tipiga o'zlashtirib beradi.fixed setprecision() funksiyasi esa sonning ma'lum bir qismini yaxlitlash imkonini yaratadi.

Quyida masala orqali tushuntirishga harakat qilaman.

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

int main() {

  /* fixed<<setprecision() - yaxlitlash funksiyasi
bo'lib quyida berilgan masala orqali qanday 
ishlashi haqida qisqacha tushuncha beraman.Nega 
pastdagi misolda 2 soni yozilgan desak ushbu
qavslar ichiga yozilgan sonning butun ishorasidan 
keyin nechta songacha yaxlitlashni anglatadi.
Masalan:
12.3273242 => fixed<<setprecision(2) => 12.33 consolega chiqadi.
*/

double son1;
float son2;
cin>>son1;
cin>>son2;
cout<<"Area is "<<fixed<<setprecision(2)<<son1*son2<<".";

return 0;
}

Console:

Son1 =>  8.25
Son2 =>  6.47

Natija: 53.38

Enter fullscreen mode Exit fullscreen mode

Ushbu keltirib o'tilgan misollar orqali round() va fixed setprecision() funksiyalari o'rtasidagi farqni va afzalliklarini qisqacha ko'rib chiqdik.

Telegram

GitHub

Top comments (2)

Collapse
muhammad40x profile image
muhammad40x

Judda ajoyib tushuntirilgan 👍🏽👍🏽

Collapse
jamolmeyliyev profile image
Jamol Meyliyev Author

thanks,

DEV runs on 100% open source code known as Forem.

 
Contribute to the codebase or host your own.
 
Check these out! 👇