round() ফাংশন double, float বা long double ভ্যালুকে নিকটতম পূর্ণসংখ্যার মানে রাউন্ড করে। হেডার: <cmath> বা <tgmath>। C++11 থেকে ওভারলোডেড ভার্সনগুলো:
- double round(double)
- float round(float)
- long double round(long double)
- double round(T) // টেমপ্লেট
নোট: রিটার্ন মান ফ্লোটিং পয়েন্টে পূর্ণসংখ্যা (যেমন 2.3 → 2.0, না যে 2)।
উদাহরণ
#include <cmath>
#include <iostream>
int main() {
double num1 = 10.5, num2 = 10.3, num3 = 9.7;
cout << "round(" << num1 << ") = " << round(num1) << "\n";
cout << "round(" << num2 << ") = " << round(num2) << "\n";
cout << "round(" << num3 << ") = " << round(num3) << "\n";
num1 = -9.3; num2 = -0.3; num3 = -9.9;
cout << "round(" << num1 << ") = " << round(num1) << "\n";
cout << "round(" << num2 << ") = " << round(num2) << "\n";
cout << "round(" << num3 << ") = " << round(num3) << "\n";
return 0;
}
আউটপুট:
round(10.5) = 11 round(10.3) = 10 round(9.7) = 10 round(-9.3) = -9 round(-0.3) = -0 round(-9.9) = -10