1 개요[ | ]
- Rounds a float
- round
- number_format
- 반올림 함수
2 C++[ | ]

C++
Copy
#include <iostream>
#include <cmath>
int main() {
std::cout << round(3.14159) << std::endl;
// 3
}
C++
Copy
#include <iostream>
#include <iomanip>
int main() {
std::cout << std::setprecision(3) << 3.14159 << std::endl;
// 3.14
std::cout << std::setprecision(5) << 123.56789 << std::endl;
// 123.57
}
3 Excel[ | ]
PHP
Copy
=ROUND(3.14159,0) // 3
=ROUND(3.14159,2) // 3.14
4 Java[ | ]

Java
Copy
int i = Math.round(1.5F); // 2
Java
Copy
String str = String.format("%.3f", 1.2345678); // 1.235
5 JavaScript[ | ]

JavaScript
Copy
console.log( Math.round(10.6) ); // 11
6 Perl[ | ]

Perl
Copy
printf("%.3f", 3.1415926535);
# 3.142
7 PHP[ | ]


PHP
Copy
echo round(7.4); // 7
echo round(7.5); // 8
echo round(7.6); // 8
PHP
Copy
echo round(7.7, 0); // 8
echo round(3.14159, 2); // 3.14
PHP
Copy
echo number_format(9.98); // 10
echo number_format(-9.98); // -10
echo number_format(1, 2); // 1.00
echo number_format(3.14159, 0); // 3
echo number_format(3.14159, 2); // 3.14
echo number_format(-3.14159, 0); // -3
echo number_format(-3.14159, 2); // -3.14
8 Python[ | ]

Python
Copy
print( round(3.14159, 2) ) # 3.14
print( round(7.4) ) # 7
print( round(7.5) ) # 8
print( round(7.6) ) # 8
print( round(7, 0) ) # 7
print( round(7, 1) ) # 7
print( round(7, 2) ) # 7
print( round(7.7, 0) ) # 8.0
print( round(7.7, 1) ) # 7.7
print( round(7.7, 2) ) # 7.7
9 SQL[ | ]
9.1 MySQL[ | ]
sql
Copy
SELECT ROUND(2.71828, 2);
-- 2.72
9.2 PostgreSQL[ | ]
10 같이 보기[ | ]
편집자 Ykhwong Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.