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);
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7730 | 10년 전 | 1301 | ||
| 7729 | 10년 전 | 1122 | ||
| 7728 |
잘살아보자
|
10년 전 | 586 | |
| 7727 |
잘살아보자
|
10년 전 | 477 | |
| 7726 |
잘살아보자
|
10년 전 | 804 | |
| 7725 |
잘살아보자
|
10년 전 | 535 | |
| 7724 |
잘살아보자
|
10년 전 | 449 | |
| 7723 |
잘살아보자
|
10년 전 | 517 | |
| 7722 |
잘살아보자
|
10년 전 | 455 | |
| 7721 |
잘살아보자
|
10년 전 | 491 | |
| 7720 |
잘살아보자
|
10년 전 | 441 | |
| 7719 |
비긴어게인
|
10년 전 | 682 | |
| 7718 |
|
10년 전 | 2518 | |
| 7717 |
잘살아보자
|
10년 전 | 640 | |
| 7716 |
잘살아보자
|
10년 전 | 388 | |
| 7715 |
잘살아보자
|
10년 전 | 422 | |
| 7714 |
잘살아보자
|
10년 전 | 469 | |
| 7713 | 10년 전 | 1773 | ||
| 7712 | 10년 전 | 1700 | ||
| 7711 | 10년 전 | 1082 | ||
| 7710 | 10년 전 | 1377 | ||
| 7709 | 10년 전 | 1501 | ||
| 7708 | 10년 전 | 1450 | ||
| 7707 | 10년 전 | 848 | ||
| 7706 |
별지기천사
|
10년 전 | 562 | |
| 7705 | 10년 전 | 1061 | ||
| 7704 |
ICONdesignstudio
|
10년 전 | 602 | |
| 7703 | 10년 전 | 576 | ||
| 7702 |
|
10년 전 | 711 | |
| 7701 | 10년 전 | 1397 | ||
| 7700 | 10년 전 | 1095 | ||
| 7699 | 10년 전 | 574 | ||
| 7698 | 10년 전 | 1122 | ||
| 7697 | 10년 전 | 5139 | ||
| 7696 | 10년 전 | 635 | ||
| 7695 | 10년 전 | 1677 | ||
| 7694 | 10년 전 | 1046 | ||
| 7693 | 10년 전 | 1539 | ||
| 7692 | 10년 전 | 1277 | ||
| 7691 | 10년 전 | 804 | ||
| 7690 | 10년 전 | 1380 | ||
| 7689 | 10년 전 | 999 | ||
| 7688 | 10년 전 | 596 | ||
| 7687 |
파랑새1597
|
10년 전 | 572 | |
| 7686 | 10년 전 | 831 | ||
| 7685 | 10년 전 | 1331 | ||
| 7684 | 10년 전 | 787 | ||
| 7683 | 10년 전 | 1066 | ||
| 7682 | 10년 전 | 980 | ||
| 7681 | 10년 전 | 642 | ||
| 7680 | 10년 전 | 981 | ||
| 7679 | 10년 전 | 490 | ||
| 7678 | 10년 전 | 718 | ||
| 7677 | 10년 전 | 620 | ||
| 7676 |
|
10년 전 | 934 | |
| 7675 |
|
10년 전 | 1152 | |
| 7674 | 10년 전 | 1040 | ||
| 7673 | 10년 전 | 743 | ||
| 7672 | 10년 전 | 1082 | ||
| 7671 | 10년 전 | 873 | ||
| 7670 | 10년 전 | 638 | ||
| 7669 |
mashmellow
|
10년 전 | 1221 | |
| 7668 | 10년 전 | 705 | ||
| 7667 | 10년 전 | 987 | ||
| 7666 |
senseme
|
10년 전 | 640 | |
| 7665 | 10년 전 | 493 | ||
| 7664 | 10년 전 | 1886 | ||
| 7663 |
mixx애교
|
10년 전 | 975 | |
| 7662 | 10년 전 | 1026 | ||
| 7661 |
hkhkah
|
10년 전 | 781 | |
| 7660 | 10년 전 | 1051 | ||
| 7659 |
커네드커네드
|
10년 전 | 917 | |
| 7658 |
바람돌이팡
|
10년 전 | 660 | |
| 7657 | 10년 전 | 1156 | ||
| 7656 | 10년 전 | 1560 | ||
| 7655 | 10년 전 | 970 | ||
| 7654 |
개발짜증나
|
10년 전 | 847 | |
| 7653 |
네이비칼라
|
10년 전 | 874 | |
| 7652 |
밥먹고합시다
|
10년 전 | 801 | |
| 7651 |
플라이SINJI
|
10년 전 | 1500 | |
| 7650 |
개발짜증나
|
10년 전 | 1400 | |
| 7649 | 10년 전 | 447 | ||
| 7648 |
이미영ㅇㅇ
|
10년 전 | 862 | |
| 7647 | 10년 전 | 419 | ||
| 7646 | 10년 전 | 788 | ||
| 7645 | 10년 전 | 2298 | ||
| 7644 | 10년 전 | 805 | ||
| 7643 |
|
10년 전 | 2861 | |
| 7642 | 10년 전 | 1499 | ||
| 7641 | 10년 전 | 1120 | ||
| 7640 |
개발짜증나
|
10년 전 | 464 | |
| 7639 |
|
10년 전 | 808 | |
| 7638 |
개발짜증나
|
10년 전 | 1123 | |
| 7637 | 10년 전 | 1540 | ||
| 7636 | 10년 전 | 2906 | ||
| 7635 | 10년 전 | 1677 | ||
| 7634 | 10년 전 | 1862 | ||
| 7633 | 10년 전 | 2320 | ||
| 7632 | 10년 전 | 3920 | ||
| 7631 |
|
10년 전 | 1523 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기