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 mu…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Jamol Meyliyev

  • 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



  • 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

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

Telegram

GitHub


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Jamol Meyliyev


Print Share Comment Cite Upload Translate Updates
APA

Jamol Meyliyev | Sciencx (2022-09-22T17:26:36+00:00) Round() and fixed setprecision() functions. Retrieved from https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/

MLA
" » Round() and fixed setprecision() functions." Jamol Meyliyev | Sciencx - Thursday September 22, 2022, https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/
HARVARD
Jamol Meyliyev | Sciencx Thursday September 22, 2022 » Round() and fixed setprecision() functions., viewed ,<https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/>
VANCOUVER
Jamol Meyliyev | Sciencx - » Round() and fixed setprecision() functions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/
CHICAGO
" » Round() and fixed setprecision() functions." Jamol Meyliyev | Sciencx - Accessed . https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/
IEEE
" » Round() and fixed setprecision() functions." Jamol Meyliyev | Sciencx [Online]. Available: https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/. [Accessed: ]
rf:citation
» Round() and fixed setprecision() functions | Jamol Meyliyev | Sciencx | https://www.scien.cx/2022/09/22/round-and-fixed-setprecision-functions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.