"반올림 함수 round()"의 두 판 사이의 차이

56번째 줄: 56번째 줄:
==Perl==
==Perl==
[[분류: Perl]]
[[분류: Perl]]
{{참고|Perl round()}}
<source lang='perl'>
<source lang='perl'>
printf("%.3f", 3.1415926535);
printf("%.3f", 3.1415926535);
# 3.142
# 3.142
</source>
==Python==
[[분류: Python]]
{{참고|파이썬 round()}}
<source lang='python'>
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
</source>
</source>



2018년 8월 26일 (일) 21:34 판

Rounds a float
round
number_format

1 Excel

=ROUND(3.14159,0) // 3
=ROUND(3.14159,2) // 3.14

2 Java

int i = Math.round(1.5F); // 2
String str = String.format("%.3f", 1.2345678); // 1.235

3 JavaScript

console.log( Math.round(10.6) ); // 11

4 PHP

echo round(7.4);         // 7
echo round(7.5);         // 8
echo round(7.6);         // 8
echo round(7.7, 0);         // 8
echo round(3.14159, 2);  // 3.14
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

5 Perl

printf("%.3f", 3.1415926535);
# 3.142

6 Python

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

7 SQL

7.1 MySQL

SELECT ROUND(2.71828, 2);
-- 2.72

7.2 PostgreSQL

8 같이 보기

9 참고