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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 3명의 중간 판 16개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[Category:수학]]
[[Category:수학]]
==개요==
;Rounds a float
;Rounds a float
;round
;round
;number_format
;number_format
*[[반올림]] 함수
*[[반올림]] 함수
==C++==
[[분류: C++]]
{{참고|C++ round()}}
<syntaxhighlight lang='cpp'>
#include <iostream>
#include <cmath>
int main() {
    std::cout << round(3.14159) << std::endl;
    // 3
}
</syntaxhighlight>
<syntaxhighlight lang='cpp'>
#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
}
</syntaxhighlight>


==Excel==
==Excel==
[[Category:Excel]]
[[Category:Excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
=ROUND(3.14159,0) // 3
=ROUND(3.14159,0) // 3
=ROUND(3.14159,2) // 3.14
=ROUND(3.14159,2) // 3.14
</source>
</syntaxhighlight>


==Java==
==Java==
[[Category:Java]]
[[Category:Java]]
<source lang='java'>
{{참고|자바 round()}}
<syntaxhighlight lang='java'>
int i = Math.round(1.5F); // 2
int i = Math.round(1.5F); // 2
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
String str = String.format("%.3f", 1.2345678); // 1.235
String str = String.format("%.3f", 1.2345678); // 1.235
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
{{참고|JavaScript Math.round()}}
[[category:JavaScript]]
[[category:JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( Math.round(10.6) ); // 11
console.log( Math.round(10.6) ); // 11
</source>
</syntaxhighlight>
 
==Perl==
[[분류: Perl]]
{{참고|Perl round()}}
<syntaxhighlight lang='perl'>
printf("%.3f", 3.1415926535);
# 3.142
</syntaxhighlight>


==PHP==
==PHP==
31번째 줄: 64번째 줄:
{{참고|PHP number_format()}}
{{참고|PHP number_format()}}
[[Category:PHP]]
[[Category:PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
echo round(7.4);        // 7
echo round(7.4);        // 7
echo round(7.5);        // 8
echo round(7.5);        // 8
echo round(7.6);        // 8
echo round(7.6);        // 8
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
echo round(7.7, 0);        // 8
echo round(7.7, 0);        // 8
echo round(3.14159, 2);  // 3.14
echo round(3.14159, 2);  // 3.14
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
echo number_format(9.98);  // 10
echo number_format(9.98);  // 10
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, 0);  // 3
echo number_format(3.14159, 2);  // 3.14
echo number_format(3.14159, 2);  // 3.14
echo number_format(-3.14159, 0);  // -3
echo number_format(-3.14159, 0);  // -3
echo number_format(-3.14159, 2);  // -3.14
echo number_format(-3.14159, 2);  // -3.14
</source>
</syntaxhighlight>
 
==Python==
[[분류: Python]]
{{참고|파이썬 round()}}
<syntaxhighlight 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
</syntaxhighlight>


==SQL==
==SQL==
53번째 줄: 108번째 줄:
===MySQL===
===MySQL===
[[Category:MySQL]]
[[Category:MySQL]]
<source lang='sql'>
<syntaxhighlight lang='sql'>
SELECT ROUND(2.71828, 2);
SELECT ROUND(2.71828, 2);
-- 2.72
-- 2.72
</source>
</syntaxhighlight>


===PostgreSQL===
===PostgreSQL===
63번째 줄: 118번째 줄:


==같이 보기==
==같이 보기==
*[[floor]]
* [[함수 floor()]]
*[[ceil]]
* [[함수 ceil()]]
*[[byte to kilobyte]]
* [[함수 toFixed()]]
*[[반올림]]
* [[byte to kilobyte]]
 
* [[반올림]]
==참고 자료==
*http://eqcode.com/wiki/Round

2020년 11월 2일 (월) 02:31 기준 최신판

1 개요[ | ]

Rounds a float
round
number_format

2 C++[ | ]

#include <iostream>
#include <cmath>
int main() {
    std::cout << round(3.14159) << std::endl;
    // 3
}
#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[ | ]

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

4 Java[ | ]

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

5 JavaScript[ | ]

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

6 Perl[ | ]

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

7 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

8 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

9 SQL[ | ]

9.1 MySQL[ | ]

SELECT ROUND(2.71828, 2);
-- 2.72

9.2 PostgreSQL[ | ]

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}