기초 테스트2
round
주어진 값을 주어진 자리 아래에서 반올림 하여 반환
Returns the rounded value of val to specified precision
echo round(1.95583, 2); // 1.96?>
문제> round 를 사용하지 않고 위와 동일한 문제에 동일한 답이 나오도록 처리하세요.
제한시간 - 2시간
댓글 16개
14년 전
ㅠㅠ 저만 풀면 좀 그런거 같은데
14년 전
어때요.... 다 같은 답이 나오는 것도 아니고 ..
그냥 풀면 됩니다.
그냥 풀면 됩니다.
14년 전
디자이너로써 그냥>>
if 소수점 3자리째의 수가 5이상이면 2자리수에 +1시켜서 두자리수 까지만 출력해라.
else 이면 그냥 소수점두자리수까지만 표현해라.
라고 답글달아봅니다 ㅋ
if 소수점 3자리째의 수가 5이상이면 2자리수에 +1시켜서 두자리수 까지만 출력해라.
else 이면 그냥 소수점두자리수까지만 표현해라.
라고 답글달아봅니다 ㅋ
JMoon
14년 전
echo "1.96";
ㅋㅅㅋ......
ㅋㅅㅋ......
14년 전
이건 쉽네요... ((int)1.95583 * (10 ^ 2) +9))/ 100)
14년 전
echo xround(1.95583, 2);
function xround($rtn,$slength) {
$temp=1;
for ($i=1; $i<=$slength; $i++) $temp=$temp*10;
$rtn=$rtn*$temp+0.5;
return ((int) $rtn/$temp );
}
검사는 안해봣음 --; 대충 맞을것 같음
---> 검사해봄 잘됨
function xround($rtn,$slength) {
$temp=1;
for ($i=1; $i<=$slength; $i++) $temp=$temp*10;
$rtn=$rtn*$temp+0.5;
return ((int) $rtn/$temp );
}
검사는 안해봣음 --; 대충 맞을것 같음
---> 검사해봄 잘됨
14년 전
제한시간도 생겼네요 ㅠㅠ
최대한 네이티브로 했는데 is_numeric 은 예외처리로 끼워넣은거니까 봐주세요.
function round_custom($num,$pos=1){
if((int)$pos < 0) return 0;
if(is_numeric($num) == FALSE){
return 0;
}
$pos_helper = 1;
for($i = 0;$i<$pos;$i++){
$pos_helper*=10;
}
$constant_int_helper = 10;
$temp_var1 = (int)(($num*$pos_helper*$constant_int_helper + (($num*$pos_helper*$constant_int_helper)%10>4?10:-10))/$constant_int_helper)/$pos_helper;
return $temp_var1;
}
최대한 네이티브로 했는데 is_numeric 은 예외처리로 끼워넣은거니까 봐주세요.
function round_custom($num,$pos=1){
if((int)$pos < 0) return 0;
if(is_numeric($num) == FALSE){
return 0;
}
$pos_helper = 1;
for($i = 0;$i<$pos;$i++){
$pos_helper*=10;
}
$constant_int_helper = 10;
$temp_var1 = (int)(($num*$pos_helper*$constant_int_helper + (($num*$pos_helper*$constant_int_helper)%10>4?10:-10))/$constant_int_helper)/$pos_helper;
return $temp_var1;
}
14년 전
echo ((int)((1.95583 * 100) + .9)) / 100;
14년 전
echo (int)((1.95583 + 0.005) * 100) / 100;
14년 전
function banOlim($num, $r){
$roundingplace = pow(10,$r);
$num = $num*$roundingplace;
$num = ceil($num);
return $num / $roundingplace;
}
echo banOlim(1.95583, 2);
$roundingplace = pow(10,$r);
$num = $num*$roundingplace;
$num = ceil($num);
return $num / $roundingplace;
}
echo banOlim(1.95583, 2);
14년 전
pow라는 함수가 있군요..... 허허~! 몰라서 for문 돌림 --;
ceil 은 반올림이 아닌것으로 이상합니다만.
banOlim(1.95583, 4) 해보시면 올림으로 나옵니다.
ceil 은 반올림이 아닌것으로 이상합니다만.
banOlim(1.95583, 4) 해보시면 올림으로 나옵니다.
14년 전
<?
function xround($float, $precision=0) {
$num = pow(10, $precision);
return (int)(($float + (0.5 / $num)) * $num) / $num;
}
echo xround(1.95583, 2);
function xround($float, $precision=0) {
$num = pow(10, $precision);
return (int)(($float + (0.5 / $num)) * $num) / $num;
}
echo xround(1.95583, 2);
14년 전
echo number_format(1.95583, 2);
14년 전
WoW !!!
14년 전
printf("%0.2f", 1.95583);
오리궁대짝
14년 전
sprintf("%01.2f", 1.95583);
게시글 목록
| 번호 | 제목 |
|---|---|
| 25847 | |
| 25846 | |
| 25845 | |
| 25844 | |
| 25843 | |
| 25842 | |
| 25836 | |
| 25835 | |
| 25834 | |
| 25833 | |
| 25832 | |
| 14405 | |
| 25831 | |
| 1550 | |
| 1543 | |
| 14404 |
JavaScript
[매뉴얼] PHP 매뉴얼 사이트 링크
|
| 29712 | |
| 1540 | |
| 14401 | |
| 25830 | |
| 1536 | |
| 29709 |
HTML
https 적용시
2
|
| 25829 | |
| 25828 | |
| 25827 | |
| 25826 | |
| 25814 | |
| 25808 | |
| 25805 | |
| 25793 | |
| 24106 | |
| 14398 | |
| 25791 | |
| 25775 | |
| 1529 | |
| 25774 | |
| 25772 | |
| 25770 | |
| 25768 | |
| 1520 | |
| 1517 | |
| 25767 | |
| 1511 | |
| 24098 | |
| 1508 | |
| 14388 | |
| 29702 | |
| 1495 | |
| 24095 | |
| 25761 | |
| 25750 | |
| 25743 | |
| 1492 | |
| 25742 | |
| 14386 | |
| 25739 | |
| 25738 | |
| 25737 | |
| 14383 | |
| 14382 | |
| 25736 | |
| 1483 | |
| 1480 | |
| 14376 | |
| 29696 |
HTML
자바스크립트 고급 팁&트릭 모음
5
|
| 24092 | |
| 24088 | |
| 24087 | |
| 1467 | |
| 1457 | |
| 1455 | |
| 1448 | |
| 1445 | |
| 1440 | |
| 29694 |
HTML
그누보드 프로그램 교육해주실 분
1
|
| 1435 | |
| 25735 | |
| 1431 | |
| 14373 |
jQuery
슬라이딩 관련 하여 찾아 보다 문의 드립니다.
2
|
| 24086 | |
| 25732 | |
| 24083 | |
| 1425 | |
| 25729 | |
| 14368 | |
| 14363 |
기타
자바관련사이트
4
|
| 1423 | |
| 24079 | |
| 14360 |
MySQL
mysql 질문이요 ?
2
|
| 25726 | |
| 29687 |
HTML
모바일웹으로 포워딩하는 스크립트
6
|
| 1418 | |
| 14355 |
Flash
플래시 xml연동 최신글 글자 선명하게
4
|
| 1416 | |
| 1414 | |
| 24077 | |
| 14354 |
JavaScript
3단셀렉트 오류문의를 드립니다.
|
| 25722 | |
| 25720 | |
| 25719 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기